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);
}
}

橙子主题打折出售

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

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

留言板

发表回复

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

热门文章

Sql Server 部署SSIS包完成远程数据传输 本篇介绍如何使用SSIS和作业完成自动更新目标数据任务。**温馨提示:如需转载本文,请注明...SqlServer部署SSIS包完成远程数据传输 作者:Pastore Antonio
1726 浏览量
SharePoint2010升级到SharePoint2013操作手册 SharePoint2010升级到SharePoint2013操作手册目录第一章...SharePoint2010升级到SharePoint2013操作手册 作者:Pastore Antonio
1698 浏览量
C# DataTable 某一列求和 列为数字类型doubletotal=Convert.ToDouble(datatable.Com...C#DataTable某一列求和 作者:Pastore Antonio
1673 浏览量
修复moss本机访问SharePoint 401.1 HTTP错误 环境:DCServer&...修复moss本机访问SharePoint401.1HTTP错误 作者:Pastore Antonio
1661 浏览量
从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 这一篇是从0开始搭建SQLServerAlwaysOn的第三篇,这一篇才真正开始搭建Alway...从0开始搭建SQLServerAlwaysOn第三篇(配置AlwaysOn) 作者:Pastore Antonio
1627 浏览量