Click here to Skip to main content
15,867,308 members
Articles / Programming Languages / C#
Article

CueProvider

Rate me:
Please Sign up or sign in to vote.
4.79/5 (26 votes)
24 Jul 2008CPOL 151.5K   4.1K   81   57
A lightweight class that lets you add cues to a TextBox.

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.

CueProvider demo

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.

C#
// Set cue text
CueProvider.SetCue (theTextBox, theCueText);

// Clear cue text
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

  • 24 Jul 2008
  • Updated the "How to use" section.

  • 17 Jul 2008
  • Initial version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Canada Canada
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.

Comments and Discussions

 
AnswerRe: Not working... Pin
Ravi Bhavnani27-Jul-08 13:05
professionalRavi Bhavnani27-Jul-08 13:05 
GeneralNice Post... Pin
Pankaj Nikam21-Jul-08 23:18
professionalPankaj Nikam21-Jul-08 23:18 
GeneralRe: Nice Post... Pin
Ravi Bhavnani22-Jul-08 7:51
professionalRavi Bhavnani22-Jul-08 7:51 
GeneralUsefull Pin
HiMik200316-Jul-08 23:50
HiMik200316-Jul-08 23:50 
GeneralRe: Usefull Pin
Ravi Bhavnani17-Jul-08 3:43
professionalRavi Bhavnani17-Jul-08 3:43 
GeneralNot working in XP - VS 2005 Pin
J a a n s16-Jul-08 21:49
professionalJ a a n s16-Jul-08 21:49 
GeneralRe: Not working in XP - VS 2005 Pin
Ravi Bhavnani17-Jul-08 3:42
professionalRavi Bhavnani17-Jul-08 3:42 
GeneralSample doesnot work, Pin
ring_016-Jul-08 20:44
ring_016-Jul-08 20:44 
I don't know what is wrong with it but didn't work as said.

Man having 1 bit brain with parity error

GeneralRe: Sample doesnot work, Pin
J a a n s16-Jul-08 21:38
professionalJ a a n s16-Jul-08 21:38 
GeneralRe: Sample doesnot work, Pin
johannesnestler16-Jul-08 23:42
johannesnestler16-Jul-08 23:42 
GeneralRe: Sample doesnot work, Pin
Ravi Bhavnani17-Jul-08 3:43
professionalRavi Bhavnani17-Jul-08 3:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.