在Windows窗体应用程序(.net)中单击图像的X/Y坐标

时间:2022-07-23 21:20:36

Is there a way to tell what x/y coordinates were clicked in a FORMS application?

是否有一种方法可以说明在表单应用程序中单击了x/y坐标?

3 个解决方案

#1


6  

Take a look at the MouseEventArgs class. Specifically the GetPosition method. The example on MSDN is using onMouseMove, but you should be able to do the same with onMouseClick. Or just use the MouseClick event of the form.

看一下MouseEventArgs类。特别是GetPosition方法。MSDN上的例子是使用onMouseMove,但是您应该能够在onMouseClick上执行相同的操作。或者只是使用表单的MouseClick事件。

E.g. using the MouseClick event:

使用MouseClick事件:

On your form:

在你的形式:

this.MouseClick += new MouseEventHandler(myForm_MouseClick);

void myForm_MouseClick(object sender, MouseEventArgs e)
{
    int myX = e.X;
    int myY = e.Y;
}

#2


3  

The MouseDown, MouseUp and MouseClick events all return the X and Y coordinates of the action.

MouseDown, MouseUp和MouseClick事件都返回了动作的X和Y坐标。

#3


2  

Look at System.Windows.Forms.Control.MousePosition (static property)

看看System.Windows.Forms.Control。MousePosition(静态属性)

#1


6  

Take a look at the MouseEventArgs class. Specifically the GetPosition method. The example on MSDN is using onMouseMove, but you should be able to do the same with onMouseClick. Or just use the MouseClick event of the form.

看一下MouseEventArgs类。特别是GetPosition方法。MSDN上的例子是使用onMouseMove,但是您应该能够在onMouseClick上执行相同的操作。或者只是使用表单的MouseClick事件。

E.g. using the MouseClick event:

使用MouseClick事件:

On your form:

在你的形式:

this.MouseClick += new MouseEventHandler(myForm_MouseClick);

void myForm_MouseClick(object sender, MouseEventArgs e)
{
    int myX = e.X;
    int myY = e.Y;
}

#2


3  

The MouseDown, MouseUp and MouseClick events all return the X and Y coordinates of the action.

MouseDown, MouseUp和MouseClick事件都返回了动作的X和Y坐标。

#3


2  

Look at System.Windows.Forms.Control.MousePosition (static property)

看看System.Windows.Forms.Control。MousePosition(静态属性)