Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Get Mouse Cursor Coordinates in Real Time

Get Mouse Cursor Coordinates in Real Time

Scheduled Pinned Locked Moved C#
questionlounge
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • . Offline
    . Offline
    ...---...
    wrote on last edited by
    #1

    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

    A J 2 Replies Last reply
    0
    • . ...---...

      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

      A Offline
      A Offline
      albCode
      wrote on last edited by
      #2

      try this private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { label1.Width = 150; label1.Text="x = "+ Convert.ToString(e.X) + "\t y = " +Convert.ToString(e.Y) ; }

      1 Reply Last reply
      0
      • . ...---...

        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

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • J J4amieC

          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.

          M Offline
          M Offline
          microsoc
          wrote on last edited by
          #4

          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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups