最上面的表格,一下[通过"可能? [英] Topmost form, clicking "through" possible?

查看:97
本文介绍了最上面的表格,一下[通过"可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您为previous答案是使我完成基本的工具,可以显示在鼠标大红十字会为了让更为明显坐标。红十字会是在透明形式透明背景的图像。问题是,你无法通过点击,因为它的最顶层,形成的中心实际定位鼠标XY。有什么办法如何使这项有用的,以便有通过仍显示上的光标,但点击?交

Thank you for previous answers that enabled to me complete the basic tool that shows large red cross in the mouse coordinates in order to let be more visible. The red cross is an image with transparent background in the transparent form. The problem is that you cannot click through, since its topmost and the center of form is actually positioned to mouse xy. Is there any way how to make this usable in order to have the cross still displayed on the cursor but "clickable" through?

推荐答案

您可以使用的 SetWindowLong函数设置WS_EX_TRANSPARENT窗口样式:

You can use SetWindowLong to set the WS_EX_TRANSPARENT window style:

如果分层窗口具有WS_EX_TRANSPARENT扩展窗口风格,层状窗口的形状将被忽略,鼠标事件将被传递到其它窗口的分层窗口下方

If the layered window has the WS_EX_TRANSPARENT extended window style, the shape of the layered window will be ignored and the mouse events will be passed to the other windows underneath the layered window.

$ C $的CProject有文章详细的技术。虽然它在VB.NET它应该很容易转换为C#。

CodeProject has this article detailing the technique. Though it's in VB.NET it should be easy to convert to C#.

我已经在过去使用下列code:

I have used the following code in the past:

public enum GWL
{
    ExStyle = -20
}

public enum WS_EX
{
    Transparent = 0x20,
    Layered = 0x80000
}

public enum LWA
{
    ColorKey = 0x1,
    Alpha = 0x2
}

[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr hWnd, GWL nIndex);

[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, int dwNewLong);

[DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, LWA dwFlags);

protected override void OnShown(EventArgs e)
{
    base.OnShown(e);
    int wl = GetWindowLong(this.Handle, GWL.ExStyle);
    wl = wl | 0x80000 | 0x20;
    SetWindowLong(this.Handle, GWL.ExStyle, wl);
    SetLayeredWindowAttributes(this.Handle, 0, 128, LWA.Alpha);
}

但也有人从别的地方复制。这里最重要的线在 OnShown 方法。虽然我不得不承认,该行

but it also was copied from somewhere else. The important lines here are in the OnShown method. Though I have to admit that the line

wl = wl | 0x80000 | 0x20;

是一个有点神秘,设置WS_EX_LAYERED和WS_EX_TRANSPARENT扩展样式。

is a little cryptic, setting the WS_EX_LAYERED and WS_EX_TRANSPARENT extended styles.

您可以大概也设置它像

wl = wl | WS_EX.Layered | WS_EX.Transparent;

这篇关于最上面的表格,一下[通过"可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆