tags:

views:

90

answers:

2

Hi all,

I'm trying to display the tooltip by calling "ToolTip.Show(String, IWin32Window, Point)", but I wanted to do it like what Windows explorer does - displays the tooltip at the lower left corner of the cursor.

I could get the mouse position by "MousePosition", but how could I get its lower left corner position?

Thanks,

+1  A: 

If nobody comes up with a better answer you can try this:

    toolTip1.Show("Am I where you want me to be?", this, this.PointToClient(MousePosition).X,
                                                         this.PointToClient(MousePosition).Y + Cursor.Size.Height * 2);

Adjust the text positioning by playing with the x/y parameters. It works on my machine but I'm not sure how it would look under different settings.

ToolTip fun tip: put this line in your Form's MouseMove event.

Jay Riggs
Thanks,Actually I just found out that Cursor.Size.Height could be used. But why mutiply it by 2?Will it scales with custom cursor?
I'm not sure why multipling by two works. I checked into what exactly the Cursor.Size property is (and how it relates to a user's local settings) and sort of gave up when the answer didn't come up on my first few attempts. This is why I added my warning that the code might not work on all machines!
Jay Riggs
+1  A: 

I think Explorer puts the tooltip under the cursor's hotspot so you don't have to correct the X-position. This looked good:

private void panel1_MouseClick(object sender, MouseEventArgs e) {
  int x = e.X;
  int y = e.Y + Cursor.Current.Size.Height - Cursor.Current.HotSpot.Y;
  toolTip1.Show("test", panel1, x, y);
}
Hans Passant