简体   繁体   中英

How can I make it so that the mousemove event works in c#?

I'm doing a course on Visual Studio right now and I'm at a point where I have no idea what I'm doing. this is my current code; it's supposed to make the labels have the location of where the mouse is in the picture box of my form.

private void picShowPicture_MouseMove(object sender, MouseEventArgs e)
lblX.Text = "X: " & e.X;
lblY.Text = "Y: " & e.Y;

Presumably that should be like so:

private void picShowPicture_MouseMove(object sender, MouseEventArgs e)
{
    lblX.Text = "X: " + e.X;
    lblY.Text = "Y: " + e.Y;
}

Note that that code appears to be handling an event of a PictureBox control, so it will only work if the mouse pointer is over that control and it will display the position relative to that control.

You also have to have registered the event handler, which won't happen automatically if you copied that code from somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM