通过以下代码,在窗体启动后调用方法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

最新文章

  1. 让Web页面中的编辑器支持黏贴或直接拖拽来添加图片
  2. php7 httpd 2.4 编译
  3. IIS发布WCF遇到的问题总结
  4. Javascript异步编程方法总结
  5. MD5 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)
  6. 【POJ】3415 Common Substrings
  7. 关于C++中的拷贝构造函数和赋值函数
  8. Wes7 剪裁方法
  9. A*寻路算法入门(一)
  10. caffe安装教程(Ubuntu14+GPU+pycaffe+anaconda2)
  11. Android插件化的兼容性(中):Android P的适配
  12. 用户认证--------------auth模块
  13. Ubuntu ssh-keygen 生成公钥并添加到远程服务器上
  14. 【javascript】九宫格抽奖组件设计
  15. Win7 配置免安装mysql5.7.20过程详解
  16. PS学习之制作音乐视屏
  17. JAVA中Integer类型变量比较问题
  18. MAC下配置ssh让SourceTree通过秘钥访问远程仓库
  19. Selenium2自动化测试实战序言
  20. hpu积分赛(回溯法)

热门文章

  1. Atitit.工作流系统的本质是dsl&#160;图形化的dsl&#160;&#160;4gl
  2. all things are difficult before they are easy
  3. Android 缓存目录 Context.getExternalFilesDir()和Context.getExternalCacheDir()方法
  4. org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused in android
  5. 【原创+译文】官方文档中声明的如何创建抽屉导航栏(Navigation Drawer)
  6. 通过注册的URL Scheme向目标APP传递参数
  7. LeetCode 8 String to Integer (string转int)
  8. windows 2008 r2 下面搭建 iis+sql server +php5.6 环境遇见的一些问题记录一下
  9. python基本数据结构-集合-方法
  10. JSON转换类(二)--List转换成Json、对象集合转换Json等