Reputation: 55
private void Form1_MouseEnter(object sender, EventArgs e)
{
}
e
doesn't have the properties X
and Y
.
I want when the mouse cursor move over a control it will do something.
Upvotes: 2
Views: 4188
Reputation: 17848
Use the Control.MousePosition static property as follows:
void Form1_MouseEnter(object sender, EventArgs e) {
Point screenPosition = MousePosition;
Point clientPosition = PointToClient(screenPosition);
}
Upvotes: 3
Reputation: 1185
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
Point p = e.Location;
}
Upvotes: 2
Reputation: 152596
You can get the current cursor position using the Cursor.Current
static property:
var x = Cursor.Current.Position.X;
var y = Cursor.Current.Position.Y;
Note that the MouseEnter
event only fires when the cursor enters the control boundary. That may be what you want, but your last sentence seems to indicate you want to know when the mouse moves within a control. In that case, MouseMove
may be a more appropriate event to handle.
Upvotes: 7