[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Use tooltips in C#

[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.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.