我有一个表单,我覆盖在另一个表单上,并使用透明度键将其设置为透明并单击可通过,跟踪其他表单位置并将其设置为父级。一切都很好,很愉快。
我真正想要的是这个透明且可点击的表单来接收拖放事件,但我怀疑使用TransparencyKey意味着所有鼠标事件都是点击通过,包括拖放?
到目前为止,我还没有能够自己谷歌,所以想知道这里是否有人会更清楚?
非常感谢, 伊恩。
答案 0 :(得分:-1)
Code Project Article on Transparent Click-through Forms (VB.NET)
从文章转换为C#。
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
private static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int LWA_ALPHA = 2;
private const int LWA_COLOR_KEY = 1;
var style = GetWindowLong(this.Handle, GWL_EXSTYLE)
SetWindowLong(this.Handle, GWL_EXSTYLE,
style | WS_EX_LAYERED | WS_EX_TRANSPARENT)
var percent = 0.7
var alpha = 255 * percent
SetLayeredWindowAttributes(this.Handle, 0, alpha, LWA_ALPHA)