C# 鼠标穿透窗体功能的实现方法
时间:2021-09-26 04:24:38
同样该功能需要加载命名空间
using System.Runtime.InteropServices;
private const uint WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int LWA_ALPHA = 0;
[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(
IntPtr hwnd,
int nIndex,
uint dwNewLong
);
[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(
IntPtr hwnd,
int nIndex
);
[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(
IntPtr hwnd,
int crKey,
int bAlpha,
int dwFlags
);
/// <summary>
/// 设置窗体具有鼠标穿透效果
/// </summary>
public void SetPenetrate()
{
GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
}
标签:C#,鼠标穿透窗体
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java使用poi操作excel实例解析
2022-01-26 00:15:41
Jsoup解析html实现招聘信息查询功能
2022-01-08 19:38:07
![](https://img.aspxhome.com/file/2023/9/64929_0s.png)
C语言字符串操作总结大全(超详细)
2023-07-06 15:14:56
C#基础学习系列之Attribute和反射详解
2022-07-19 17:55:40
![](https://img.aspxhome.com/file/2023/6/102156_0s.png)
IDEA快速搭建spring boot项目教程(Spring initializr)
2023-08-17 21:11:16
![](https://img.aspxhome.com/file/2023/0/58060_0s.png)
Java读取json数据并存入数据库的操作代码
2023-09-23 06:00:57
springboot整合Shiro
2022-11-13 11:07:52
![](https://img.aspxhome.com/file/2023/0/71140_0s.jpg)
C#多线程系列之线程池
2023-02-21 17:25:44
浅析Mybatis 在CS程序中的应用
2023-06-24 08:44:15
![](https://img.aspxhome.com/file/2023/2/57422_0s.jpg)
Java 面向对象和封装全面梳理总结
2023-10-16 08:20:27
判断图片-判断位图是否是黑白图片的方法
2023-06-09 17:20:07
Android程序开发之手机APP创建桌面快捷方式
2023-04-01 06:55:49
![](https://img.aspxhome.com/file/2023/0/89540_0s.png)
Java文件读写IO/NIO及性能比较详细代码及总结
2021-11-28 12:56:30
java spring mvc处理器映射器介绍
2021-11-22 01:01:35
Maven 多profile及指定编译问题的解决
2022-04-22 23:43:24
Java实现堆排序和图解
2023-11-11 12:13:37
![](https://img.aspxhome.com/file/2023/6/59336_0s.png)
C#中深拷贝和浅拷贝的介绍与用法
2022-11-04 07:42:46
![](https://img.aspxhome.com/file/2023/8/98198_0s.jpg)
springmvc图片上传及json数据转换过程详解
2022-02-25 17:11:14
![](https://img.aspxhome.com/file/2023/7/74927_0s.png)
Java中的强引用,软引用,弱引用,虚引用的作用介绍
2023-08-27 11:03:28
![](https://img.aspxhome.com/file/2023/1/58411_0s.png)
JAVA包装类及自动封包解包实例代码
2022-10-23 13:28:54