同样该功能需要加载命名空间
usingSystem.Runtime.InteropServices;
代码如下:
privateconstuintWS_EX_LAYERED=0x80000;
privateconstintWS_EX_TRANSPARENT=0x20;
privateconstintGWL_STYLE=(-16);
privateconstintGWL_EXSTYLE=(-20);
privateconstintLWA_ALPHA=0;
[DllImport(“user32″,EntryPoint=”SetWindowLong”)]
privatestaticexternuintSetWindowLong(
IntPtrhwnd,
intnIndex,
uintdwNewLong
);
[DllImport(“user32″,EntryPoint=”GetWindowLong”)]
privatestaticexternuintGetWindowLong(
IntPtrhwnd,
intnIndex
);
[DllImport(“user32″,EntryPoint=”SetLayeredWindowAttributes”)]
privatestaticexternintSetLayeredWindowAttributes(
IntPtrhwnd,
intcrKey,
intbAlpha,
intdwFlags
);
///<summary>
///设置窗体具有鼠标穿透效果
///</summary>
publicvoidSetPenetrate()
{
GetWindowLong(this.Handle,GWL_EXSTYLE);
SetWindowLong(this.Handle,GWL_EXSTYLE,WS_EX_TRANSPARENT|WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle,0,100,LWA_ALPHA);
}
您可能感兴趣的文章:C#实现随鼠标移动窗体实例C#实现获取鼠标句柄的方法C#中winform实现自动触发鼠标、键盘事件的方法浅析c#中如何在form的webbrowser控件中获得鼠标坐标用C#实现鼠标框选效果的实现代码C#禁用鼠标中间键的方法C#实现带阴历显示的日期代码c#显示当前在线人数示例C#中动态显示当前系统时间的实例方法C#实现鼠标移动到曲线图上显示值的方法
C语言高效编程的几招小技巧
C/C++实现的游戏角色名称免费精选名字大全随机生成代码
上述就是C#学习教程:C# 鼠标穿透窗体功能的实现方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/904966.html