C# 鼠标穿透窗体功能
2024-08-25 11:02:52
通过以下代码,在窗体启动后调用方法SetPenetrate() 即可实现窗体的穿透功能。
同样该功能需要加载命名空间
using System.Runtime.InteropServices;
private const uint WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-);
private const int GWL_EXSTYLE = (-);
private const int LWA_ALPHA = ; [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>
/// <param name="flag">true穿透,false不穿透</param>
public void SetPenetrate(bool flag = true)
{
uint style = GetWindowLong(this.Handle, GWL_EXSTYLE);
if (flag)
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_TRANSPARENT | WS_EX_LAYERED);
else
SetWindowLong(this.Handle, GWL_EXSTYLE, style & ~(WS_EX_TRANSPARENT | WS_EX_LAYERED));
SetLayeredWindowAttributes(this.Handle, , , LWA_ALPHA);
}
原文地址:http://bbs.csdn.net/topics/390325341
最新文章
- 让Web页面中的编辑器支持黏贴或直接拖拽来添加图片
- php7 httpd 2.4 编译
- IIS发布WCF遇到的问题总结
- Javascript异步编程方法总结
- MD5 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)
- 【POJ】3415 Common Substrings
- 关于C++中的拷贝构造函数和赋值函数
- Wes7 剪裁方法
- A*寻路算法入门(一)
- caffe安装教程(Ubuntu14+GPU+pycaffe+anaconda2)
- Android插件化的兼容性(中):Android P的适配
- 用户认证--------------auth模块
- Ubuntu ssh-keygen 生成公钥并添加到远程服务器上
- 【javascript】九宫格抽奖组件设计
- Win7 配置免安装mysql5.7.20过程详解
- PS学习之制作音乐视屏
- JAVA中Integer类型变量比较问题
- MAC下配置ssh让SourceTree通过秘钥访问远程仓库
- Selenium2自动化测试实战序言
- hpu积分赛(回溯法)
热门文章
- Atitit.工作流系统的本质是dsl&#160;图形化的dsl&#160;&#160;4gl
- all things are difficult before they are easy
- Android 缓存目录 Context.getExternalFilesDir()和Context.getExternalCacheDir()方法
- org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused in android
- 【原创+译文】官方文档中声明的如何创建抽屉导航栏(Navigation Drawer)
- 通过注册的URL Scheme向目标APP传递参数
- LeetCode 8 String to Integer (string转int)
- windows 2008 r2 下面搭建 iis+sql server +php5.6 环境遇见的一些问题记录一下
- python基本数据结构-集合-方法
- JSON转换类(二)--List转换成Json、对象集合转换Json等