Get Mouse Cursor Coordinates in Real Time
-
Hi, I want to display the coordinates of the cusor next to it as it is dragged around a WinForm. I have the following skeleton code.... ////////////////////////////////////////// private void Form_1Paint(PaintEventArgs e) { //?? What to do } protected override void OnPaint() { //?? What to do } private void OnMouseMove(MouseEventArgs e) { //?? What to do } ////////////////////////////////////// I may have gotten some Args or Access modifiers wrong, but this is the general idea...I'd appreciate any code that will get this done... thanks
-
Hi, I want to display the coordinates of the cusor next to it as it is dragged around a WinForm. I have the following skeleton code.... ////////////////////////////////////////// private void Form_1Paint(PaintEventArgs e) { //?? What to do } protected override void OnPaint() { //?? What to do } private void OnMouseMove(MouseEventArgs e) { //?? What to do } ////////////////////////////////////// I may have gotten some Args or Access modifiers wrong, but this is the general idea...I'd appreciate any code that will get this done... thanks
-
Hi, I want to display the coordinates of the cusor next to it as it is dragged around a WinForm. I have the following skeleton code.... ////////////////////////////////////////// private void Form_1Paint(PaintEventArgs e) { //?? What to do } protected override void OnPaint() { //?? What to do } private void OnMouseMove(MouseEventArgs e) { //?? What to do } ////////////////////////////////////// I may have gotten some Args or Access modifiers wrong, but this is the general idea...I'd appreciate any code that will get this done... thanks
Someone asked this last week and I still had this code in my test app which works
Point myMouse; protected override void OnPaint(PaintEventArgs e) { Point screen = PointToScreen(myMouse); string location = screen.ToString(); e.Graphics.DrawString("[Screen: " + location + "]", new Font("Arial",8), SystemBrushes.ControlText, (PointF)myMouse); } protected override void OnMouseMove(MouseEventArgs e) { myMouse = new Point(e.X,e.Y); Invalidate(); base.OnMouseMove(e); }
Just paste that into an empty form underneath the constructor and it should work. -
Someone asked this last week and I still had this code in my test app which works
Point myMouse; protected override void OnPaint(PaintEventArgs e) { Point screen = PointToScreen(myMouse); string location = screen.ToString(); e.Graphics.DrawString("[Screen: " + location + "]", new Font("Arial",8), SystemBrushes.ControlText, (PointF)myMouse); } protected override void OnMouseMove(MouseEventArgs e) { myMouse = new Point(e.X,e.Y); Invalidate(); base.OnMouseMove(e); }
Just paste that into an empty form underneath the constructor and it should work.hi there! :) i suggest that instead of using a variable and setting it to the OnMouseMove method, you can also use the MousePosition property of your control. this will return the position of your mouse cursor in screen coordinates.but if you want to convert it to your control coordinates, just use the PointToClient method and pass the MousePosition as a parameter. Hope that helps! :) Advance Merry Christmas and Happy New Year To All! :) microsoc :cool: