C#制作鼠标可以穿透的窗体
2007-04-24 02:25
357 查看
把窗体的FormBorderStyle设为FormBorderStyle.None
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 = 0x2;
[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 CanPenetrate()
{
uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE);
uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
}
要时窗体恢复正常,只要执行以下语句:
this.FormBorderStyle = FormBorderStyle.None;
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 = 0x2;
[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 CanPenetrate()
{
uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE);
uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
}
要时窗体恢复正常,只要执行以下语句:
this.FormBorderStyle = FormBorderStyle.None;
相关文章推荐
- C#制作鼠标可以穿透的窗体
- C# 鼠标穿透窗体功能
- Qt 不规则窗体 – 鼠标点击穿透(Linux也可以,有对x11的配置的方法)
- C# 鼠标穿透窗体与恢复
- 用C#写依附于桌面的透明带鼠标穿透窗体的总结。
- C# 鼠标穿透窗体功能的实现方法
- c# 鼠标穿透窗体 张宇轩
- 制作鼠标穿透窗体
- C# Winform 窗体美化(五、鼠标穿透)
- 制作鼠标穿透窗体
- C#窗体设计------鼠标穿透窗体
- C# 无边框异型窗体制作
- 设置窗体可以使用鼠标拖动大小 通过
- C#WinForm无边框窗体移动方法、模仿鼠标单击标题栏移动窗体位置
- c# 给窗体添加MouseEnter事件,可鼠标移到任意控件均会产生MouseEnter事件,如何识别是哪个产生的呢?
- c#制作飘动动画窗体
- C# winform中不规则窗体制作的解决方案(已经解决24位色以上不能正常显示问题)
- C# 事件穿透 事件冒泡 鼠标点击后在父级控件捕获
- 用C#制作飘动的窗体效果
- C#WinForm制作异形窗体/控件