Title: Use tooltips in C#
To create tooltips at design time, add a ToolTip component to a form. It adds a new property to each of the other controls on the form. In this example the ToolTip component is named tipAddress so it adds a property named ToolTip on tipAddress to each control. Set that property for a control to make that control display the tooltip. Displaying and removing tooltips at run time is automatic.
To set or change tooltips at run time, call the ToolTip component's SetToolTip method passing it the control whose tooltip you want to change and the new tooltip text. This example uses the following code to add tooltips to the buttons at runtime.
// Add tooltips to the buttons.
private void btnAddTips_Click(object sender, EventArgs e)
{
tipAddress.SetToolTip(btnAddTips,
"Click to add tooltips to the buttons.");
tipAddress.SetToolTip(btnRemoveTips,
"Click to remove tooltips from the buttons.");
}
To remove a tooltip, simply use SetToolTip to set the tooltip to a blank string as shown in the following code.
// Remove tooltips from the buttons.
private void btnRemoveTips_Click(object sender, EventArgs e)
{
tipAddress.SetToolTip(btnAddTips, "");
tipAddress.SetToolTip(btnRemoveTips, "");
}
Download the example to experiment with it and to see additional details.
|