C# 鼠標(biāo)穿透窗體功能的實(shí)現(xiàn)方法
更新時間:2013年10月08日 14:47:43 作者:
通過以下代碼,在窗體啟動后調(diào)用方法SetPenetrate() 即可實(shí)現(xiàn)窗體的穿透功能,有需要的朋友可以參考一下
同樣該功能需要加載命名空間
using System.Runtime.InteropServices;
復(fù)制代碼 代碼如下:
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>
/// 設(shè)置窗體具有鼠標(biāo)穿透效果
/// </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#實(shí)現(xiàn)圖表中鼠標(biāo)移動并顯示數(shù)據(jù)
- C#簡單獲取全屏中鼠標(biāo)焦點(diǎn)位置坐標(biāo)的方法示例
- C#實(shí)現(xiàn)的鼠標(biāo)鉤子
- C#鍵盤鼠標(biāo)鉤子實(shí)例
- C#實(shí)現(xiàn)鼠標(biāo)移動到曲線圖上顯示值的方法
- C#實(shí)現(xiàn)隨鼠標(biāo)移動窗體實(shí)例
- C#實(shí)現(xiàn)獲取鼠標(biāo)句柄的方法
- C#中winform實(shí)現(xiàn)自動觸發(fā)鼠標(biāo)、鍵盤事件的方法
- 解決C#獲取鼠標(biāo)相對當(dāng)前窗口坐標(biāo)的實(shí)現(xiàn)方法
- 用C# 實(shí)現(xiàn)鼠標(biāo)框選效果的實(shí)現(xiàn)代碼
- C# 禁用鼠標(biāo)中間鍵的方法
- C#實(shí)現(xiàn)鼠標(biāo)消息捕獲
相關(guān)文章
winfrom 在業(yè)務(wù)層實(shí)現(xiàn)事務(wù)控制的小例子
winfrom 在業(yè)務(wù)層實(shí)現(xiàn)事務(wù)控制的小例子,需要的朋友可以參考一下2013-03-03C#使用Socket發(fā)送和接收TCP數(shù)據(jù)實(shí)例
這篇文章主要介紹了C#使用Socket發(fā)送和接收TCP數(shù)據(jù)的實(shí)現(xiàn)方法,以實(shí)例的形式詳細(xì)講述了C#實(shí)現(xiàn)socket通信的完整實(shí)現(xiàn)過程,非常具有實(shí)用價值,需要的朋友可以參考下2014-10-10C#使用SqlDataAdapter對象獲取數(shù)據(jù)的方法
這篇文章主要介紹了C#使用SqlDataAdapter對象獲取數(shù)據(jù)的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了SqlDataAdapter對象獲取數(shù)據(jù)具體步驟與相關(guān)使用技巧,需要的朋友可以參考下2016-02-02C#導(dǎo)出數(shù)據(jù)到CSV文件的通用類實(shí)例
這篇文章主要介紹了C#導(dǎo)出數(shù)據(jù)到CSV文件的通用類,將C#操作CSV文件的常用技巧封裝進(jìn)一個通用類中以方便調(diào)用,非常具有實(shí)用價值,需要的朋友可以參考下2015-04-04