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
1531 浏览量
【干货】Chrome插件(扩展)开发全攻略 写在前面我花了将近一个多月的时间断断续续写下这篇博文,并精心写下完整demo,写博客的辛苦大家懂的...【干货】Chrome插件(扩展)开发全攻略 作者:Pastore Antonio
1486 浏览量
memcached 处理 多端口:https://blog.csdn.net/Erica_1230/article/deta...memcached处理 作者:Pastore Antonio
1480 浏览量
使用Nginx+WordPress搭建个人网站 背景很多研究技术的朋友喜欢写博客。如果希望搭建一个完全属于自己的网站,也并不困难。这里简要分享一下...使用Nginx+WordPress搭建个人网站 作者:Pastore Antonio
1452 浏览量
C#图片处理 通常对一幅图片的处理包括:格式变换,缩放(Scale),翻转(Rotate),截取(Clip),滤镜...C#图片处理 作者:Pastore Antonio
1443 浏览量