[英]How to make a Form in Windows Forms C# not Clickable?
我正在尝试在屏幕中间创建一个红点来进行射击游戏。 但我有一个问题。 表单窃取了点击,现在我无法进行事件拍摄! 那么有什么方法可以使表单不窃取点击? 这就是我想要做的。
static Form RedDot;
static void Main()
{
var width=Screen.PrimaryScreen.Bounds.Width;
var Height = Screen.PrimaryScreen.Bounds.Height;
RedDot = new Form();
RedDot.AutoSize = false;
RedDot.BackColor = Color.Red;
RedDot.FormBorderStyle = FormBorderStyle.None;
RedDot.ShowInTaskbar = false;
RedDot.Size = new Size(3,3);
RedDot.Location = new Point(width/2, Height/2);
RedDot.TopMost = true;
RedDot.Shown += new EventHandler(RedDot_Shown);
Application.EnableVisualStyles();
Application .Run(RedDot);
}
static void RedDot_Shown(object sender, EventArgs e)
{
RedDot.Size = new Size(3,3);
}
您可以为 RedDot 表单分配一个事件处理程序,用于单击以调用触发逻辑。 假设您在主窗体上有点击事件。
static void Form_Click(object sender, EventArgs e)
{
// some firing stuff
}
将触发逻辑移到新方法中。
static void Firing(long x, long y)
{
// some firing stuff
}
static void Form_Click(object sender, EventArgs e)
{
Firing(e.somethingX,e.somethingY);
}
所以现在你可以为 RedDot 表单创建点击事件并调用 Firing 方法。
static void Main()
{
//...
RedDot.Shown += new EventHandler(RedDot_Shown);
RedDot.Click += RedDot_Click;
//...
}
static void RedDot_Click(object sender, EventArgs e)
{
Firing(e.somethingX,e.somethingY);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.