[英]Make Monogame window click-through
我是 MonoGame 的新手,我正在尝试制作叠加层(最顶层、透明和点击)。 我设法做了前两件事,但做不到第三件事。
这是我试过的:
internal class User32 {
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}
public class Game1 : Game
{
public IntPtr FormHandle { get; private set; }
public Form Form { get; private set; }
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
FormHandle = this.Window.Handle;
Form = (Form)Form.FromHandle(FormHandle).FindForm();
//make it topmost and click-through
Form.TopMost = true;
int initialStyle = User32.GetWindowLong(Form.Handle, -20);
User32.SetWindowLong(Form.Handle, -20, initialStyle | 0x80000 | 0x20);
//make it transparent and borderless
Form.BackColor = System.Drawing.Color.Black;
//Form.TransparencyKey = System.Drawing.Color.Black;
Form.Opacity = 0.5;
Form.FormBorderStyle = FormBorderStyle.None;
base.Initialize();
}
[...]
}
这是我找到的唯一方法。 它适用于我拥有的 windows 表单应用程序,但不适用于 monogame。 有什么想法吗?
编辑:我刚刚意识到 window 是点击,但只有绘制区域不是。 我只有png背景,它的透明区域是点击通过的,但彩色区域不是
尝试将您的代码复制到构造函数并一次性更新。 window 在构造后初始化,大部分属性在构造后内部设置。 有些是后来设置的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.