Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo, I want to display a tooltip, when i hover on picturebox. But the problem is, that I want to show it only on current mouse position.

Code:
C#
private void picturebox1_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();

            if (e.X >= 18 && e.X <= 71 && e.Y >= 21 && e.Y <= 79)
            {
                tt.SetToolTip(this.picturebox1, "something");
            }

            else
            {
                tt.Hide(this.picturebox1);
            }
        }


But Mouse_Hover do not respond on mouse position e.x and e.y and Mouse_Move show it everytime, when cursor moves... Thanks for answer.
Posted

1 solution

Yes the MouseHover event does not use the MouseEventHandler so you don't get the e.x and e.y. Another way to do this is to get the Cursors position, and since your in a form use PointToClient to get the correct location.

C#
private void picturebox1_MouseHover(object sender, EventArgs e)
{
    ToolTip tt = new ToolTip();
    Point p = pictureBox1.PointToClient(System.Windows.Forms.Cursor.Position);

    if (p.X >= 18 && p.X <= 71 && p.Y >= 21 && p.Y <= 79)
    {
        tt.SetToolTip(this.picturebox1, "something");
    }

    else
    {
        tt.Hide(this.picturebox1);
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900