Display a tool tip on current document
I am developing a code edit开发者_StackOverflowor like VS. I want to display a tool tip window when mouse cursor lands on a text. The ToolTip.Show()
method asks for a IWin32Window parameter...
Please tell me how to display the tool tip in the current document just as Visual Studio Intellisense works.
The ToolTip.Show
method also has other more appropriate overloads, like this one.
You can pass the edit control (that is, your text box) that you want to be associated with the tooltip as the IWin32Window
parameter.
Then, you can specify the current coordinates of the mouse cursor as the X
and Y
arguments:
If you're trying to show this tooltip in one of the mouse event handlers (like
MouseMove
), the current coordinates of the mouse cursor are passed in as part of theMouseEventArgs
—just use thee.X
ande.Y
properties.Otherwise, you'll need to use the
Control.MousePosition
property to get its current location, which will return aPoint
representing its current location relative to screen coordinates. Another one of the overloads to theToolTip.Show
method accepts aPoint
parameter that you can use here instead of separate X and Y coordinates
ToolTip.Show
Method (String, IWin32Window)
The second argument is the control for which the tool tip is to be shown.
toolTip1.Show("Test 123", button1, Int32.MaxValue);
Visual Studio tracks the word underneath the mouse and displays tooltips/intellisense accordingly. One way for you to do the same could be to:
- Track the mouse movements
- Get the text under mouse
- Show tooltip.
精彩评论