BLOG.CSHARPHELPER.COM: Use tooltips and change them at run time in C#
Use tooltips and change them at run time in C#
To create tooltips, 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 the text that you want to use as a tooltip for that control. The rest is automatic.
To set or change a tooltip at run time, call the ToolTip component's SetToolTip method passing it the control whose tooltip you want to change and the tooltip's new 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, ""); }
Comments