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
1617 浏览量
EWS(Exchange Service)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 最近公司要求和exchange服务对接,所以稍微研究了一下官方文档,做出以下总结,欢迎大家补充。先...EWS(ExchangeService)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 作者:Pastore Antonio
1611 浏览量
SharePoint2010升级到SharePoint2013操作手册 SharePoint2010升级到SharePoint2013操作手册目录第一章...SharePoint2010升级到SharePoint2013操作手册 作者:Pastore Antonio
1597 浏览量
SQL Server AG集群启动不起来的临时自救大招 背景前晚一朋友遇到AG集群发生来回切换不稳定的情况,情急之下,朋友在命令行使用命令重启WSFC集群...SQLServerAG集群启动不起来的临时自救大招 作者:Pastore Antonio
1596 浏览量
C# DataTable 某一列求和 列为数字类型doubletotal=Convert.ToDouble(datatable.Com...C#DataTable某一列求和 作者:Pastore Antonio
1584 浏览量