-1

我想在我的 winform 应用程序中的图像上创建一个热点。我遵循了HERE发布的解决方案,但我不知道应该将坐标放在哪里才能使此方法起作用:

protected override void OnMouseMove(MouseEventArgs mouseEvent) 
{ 
     string X = mouseEvent.X.ToString();
     string Y = mouseEvent.Y.ToString(); 
}

我应该把坐标放在哪里?我有两个坐标 (X,Y): 110, 45

4

2 回答 2

3

如果您想响应鼠标在图像中的矩形上方:

private Rectangle _hotspot = new Rectangle(20, 30, 10, 10);

protected override void OnMouseDown(MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        if (_hotspot.Contains(e.Location))
        {
            // respond to the mouse being in the hotspot
        }
    }
}
于 2012-07-04T08:28:08.417 回答
0

如果要将图像放置在这些坐标上,则需要使用这些坐标设置该图像的顶部和左侧

double X = mouseEvent.X;
double Y = mouseEvent.Y;

pictureBox.Top = X;
pictureBox.Left = Y;

如果您只想知道例如当有人在图片框上徘徊时,请使用此事件

private void pictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{

 // do here what you want
}
于 2012-07-04T08:21:13.390 回答