gpt4 book ai didi

c# - 我制作了一个矩形如何检查鼠标是否点击了它?

转载 作者:行者123 更新时间:2023-12-05 09:20:17 25 4
gpt4 key购买 nike

如何检查鼠标是否点击了矩形?

Graphics gfx;
Rectangle hitbox;
hitbox = new hitbox(50,50,10,10);
//TIMER AT THE BOTTOM
gfx.Draw(System.Drawing.Pens.Black,hitbox);

最佳答案

如果您的“gfx”是来自表单的“e.Graphics...”,只是一个快速而肮脏的示例:

  public partial class Form1 : Form
{
private readonly Rectangle hitbox = new Rectangle(50, 50, 10, 10);
private readonly Pen pen = new Pen(Brushes.Black);

public Form1()
{
InitializeComponent();
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(pen, hitbox);
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if ((e.X > hitbox.X) && (e.X < hitbox.X + hitbox.Width) &&
(e.Y > hitbox.Y) && (e.Y < hitbox.Y + hitbox.Height))
{
Text = "HIT";
}
else
{
Text = "NO";
}
}
}

关于c# - 我制作了一个矩形如何检查鼠标是否点击了它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38319092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com