Display a tooltip over a button using Windows Forms
How can I display a tooltip over a button using Windows Forms?
The ToolTip is a single WinForms control that handles displaying tool tips for multiple elements on a single form.
Say your button is called MyButton.
- Add a ToolTip control (under Common Controls in the Windows Forms toolbox) to your form.
- Give it a name - say MyToolTip
- Set the "Tooltip on MyToolTip" property of MyButton (under Misc in the button property grid) to the text that should appear when you hover over it.
The tooltip will automatically appear when the cursor hovers over the button, but if you need to display it programmatically, call
MyToolTip.Show("Tooltip text goes here", MyButton);
in your code to show the tooltip, and
MyToolTip.Hide(MyButton);
to make it disappear again.
Using the form designer:
- Drag the ToolTip control from the Toolbox, onto the form.
- Select the properties of the control you want the tool tip to appear on.
- Find the property 'ToolTip on toolTip1' (the name may not be toolTip1 if you changed it's default name).
- Set the text of the property to the tool tip text you would like to display.
You can set also the tool tip programatically using the following call:
this.toolTip1.SetToolTip(this.targetControl, "My Tool Tip");
You can use the ToolTip class:
Creating a ToolTip for a Control
Example:
private void Form1_Load(object sender, System.EventArgs e)
{
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.Button1, "Hello");
}
For default tooltip this can be used -
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.textBox1, "Hello world");
A customized tooltip can also be used in case if formatting is required for tooltip message. This can be created by custom formatting the form and use it as tooltip dialog on mouse hover event of the control. Please check following link for more details -
http://newapputil.blogspot.in/2015/08/create-custom-tooltip-dialog-from-form.html