[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: Display tips in a status bar instead of a tooltip in C#

[Display tips in a status bar instead of a tooltip in C#]

A tooltip provides information when a user needs it but remains unobtrusive when the user doesn't need the information. For example, normally you can chug through a form filling in fields such as Name, Street, City, and State without any problem. However, if you get confused when you reach the "Oh hai!" field, you can hover the mouse over it to see a tooltip explaining what you should put in that field. Tooltips do such a good job of providing unobtrusive hints that they have been around virtually unchanged for decades.

Another method for providing hints even less obtrusively is to display tips message in a status label. When focus moves to a TextBox or the mouse moves over a button, you can display a tip in the status label. Experienced users can easily ignore that message but it's instantly there for anyone who is confused.

In this example, the toolstrip buttons have tips stored in their Tag properties. The program uses the following code to display and remove the tips when the mouse enters or leaves a button.

// Set the button's status tip. private void btn_MouseEnter(object sender, EventArgs e) { ToolStripButton btn = sender as ToolStripButton; lblStatusTip.Text = btn.Tag.ToString(); } // Remove the button's status tip. private void btn_MouseLeave(object sender, EventArgs e) { lblStatusTip.Text = ""; }

All of the example's toolstrip buttons share these two event handlers. When the mouse moves over a button, the btn_MouseEnter event handler fires. It converts the sender parameter into the TooStripButton that raised the event. It then displays that button's Tag value in the status strip label lblStatusTip.

When the mouse leaves a button, the btnNew_MouseLeave event handler clears the text in lblStatusTip.

Download the example to experiment with it and to see additional details.

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