Introduction
CueProvider
is a tiny class that lets you set a cue banner (the grey prompt text that automatically disappears when you begin to type) in a TextBox
control.
How to use CueProvider
CueProvider
is easy to use, and has just two methods - one to set a TextBox
's cue text, the other to clear it. To set the cue text, call SetCue()
; to clear it, call ClearCue()
. These calls are best placed in your form's OnLoad
handler.
CueProvider.SetCue (theTextBox, theCueText);
CueProvider.ClearCue (theTextBox);
How it works
CueProvider
works by sending the TextBox
the EM_SETCUEBANNER
message. The message is sent using the SendMessage()
Win32 API. More information on the EM_SETCUEBANNER
message can be found on this MSDN page.
Conclusion
As you can see, there's nothing overly complicated in this class. I put CueBanner
together in a few minutes, and wanted to share it with the CodeProject community in the hope it could help give our desktop apps a bit of UI "polish".
Revision history
Ravi Bhavnani is an ardent fan of Microsoft technologies who loves building Windows apps, especially PIMs, system utilities, and things that go bump on the Internet. During his career, Ravi has developed expert systems, desktop imaging apps, marketing automation software, EDA tools, a platform to help people find, analyze and understand information, trading software for institutional investors and advanced data visualization solutions. He currently works for a company that provides enterprise workforce management solutions to large clients.
His interests include the .NET framework, reasoning systems, financial analysis and algorithmic trading, NLP, HCI and UI design. Ravi holds a BS in Physics and Math and an MS in Computer Science and was a Microsoft MVP (C++ and C# in 2006 and 2007). He is also the co-inventor of 3 patents on software security and generating data visualization dashboards. His claim to fame is that he crafted CodeProject's "joke" forum post icon.
Ravi's biggest fear is that one day he might actually get a life, although the chances of that happening seem extremely remote.