Logo

C# 透明穿透窗体

photo

2024年12月18日

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class TransparentFullScreenForm : Form
{
[DllImport(“user32.dll”)]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("user32.dll")]
private static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags);

private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int 1 = 0;
private const int 255 = 255;
private const uint LWA_ALPHA = 0x2;

public TransparentFullScreenForm()
{
    this.StartPosition = FormStartPosition.Manual;
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.SetWindowLong();
    this.SetLayeredWindowAttributes();
}

private void SetWindowLong()
{
    IntPtr windowLongPtr = GetWindowLong(this.Handle, GWL_EXSTYLE);
    int windowStyle = WS_EX_LAYERED | WS_EX_TRANSPARENT;
    SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)windowStyle);
}

private void SetLayeredWindowAttributes()
{
    SetLayeredWindowAttributes(this.Handle, 0, 128, LWA_ALPHA);
}

}

public static class Program
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
TransparentFullScreenForm form = new TransparentFullScreenForm();
Application.Run(form);
}
}

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它
所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

留言板

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

热门文章

WordPress 后台编辑器样式实现直接预览 在WordPress3.0以后,有一个新的实用功能:你可以更改默认后台编辑器(TinyMCE)的样...WordPress后台编辑器样式实现直接预览 作者:Pastore Antonio
1613 浏览量
又到泡桐花开时 暮春四月,百花争艳,千姿百态,香飘千里,万木争荣。有一种泡桐树,迟于阳春三月里盛开的桃树、杏树、李树,欣欣然,翩翩然,花开芬芳,来到五彩缤纷姹紫嫣红的大自然界,向人们一展芳姿,怒放于中原大地,成为晚春时节一道靓丽的风景线。 作者:Pastore Antonio
1590 浏览量
C#图片处理 通常对一幅图片的处理包括:格式变换,缩放(Scale),翻转(Rotate),截取(Clip),滤镜...C#图片处理 作者:Pastore Antonio
1582 浏览量
【干货】Chrome插件(扩展)开发全攻略 写在前面我花了将近一个多月的时间断断续续写下这篇博文,并精心写下完整demo,写博客的辛苦大家懂的...【干货】Chrome插件(扩展)开发全攻略 作者:Pastore Antonio
1568 浏览量
memcached 处理 多端口:https://blog.csdn.net/Erica_1230/article/deta...memcached处理 作者:Pastore Antonio
1563 浏览量