我是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。有什么想法吗?
编辑:我刚刚意识到窗口是通过点击,但只有绘制区域不是。我只有png背景,它的透明区域是通过点击,但彩色区域不是。
发布于 2022-11-21 05:19:15
尝试将您的代码复制到构造函数和更新中的一次。该窗口在创建后初始化,大多数属性在构建后在内部设置。有些是晚些时候设定的。
https://stackoverflow.com/questions/74514247
复制相似问题