Search code examples
c#winformscursor

Text under mouse cursor on PictureBox


I have a problem with displaying the text under the mouse cursor on Picture Box. I want to dynamically display the mouse coordinates under the cursor.

I'm trying to display text by label and change the label's position when a "MouseMove" event happens.

 private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {            
        label1.Location = new Point(e.X + 10, e.Y + 10);
    }

But, I think, it is a bad solution... And although it works it hides other output when we move the cursor

Thanks a lot!


Solution

  • Thanks for Thomas's advice, here code to display mouse coordinate under cursor:

    ToolTip tt = new ToolTip();
    tt.SetToolTip(pic, " ");
    tt.ShowAlways = true;
    
     private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
     {
        tt.ToolTipTitle = e.X + "  " + e.Y; 
     }