Click here to Skip to main content
14,271,759 members

CueProvider

Rate this:
4.79 (25 votes)
Please Sign up or sign in to vote.
4.79 (25 votes)
24 Jul 2008CPOL
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.

// 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)

Share

About the Author

Ravi Bhavnani
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

 
GeneralRe: not workin Pin
Ravi Bhavnani25-Jul-08 6:40
professionalRavi Bhavnani25-Jul-08 6:40 
GeneralI modified it to do an IExtenderProvider component [modified] Pin
Fabrice CARUSO24-Jul-08 20:11
memberFabrice CARUSO24-Jul-08 20:11 
GeneralRe: I modified it to do an IExtenderProvider component Pin
Ravi Bhavnani25-Jul-08 6:39
professionalRavi Bhavnani25-Jul-08 6:39 
GeneralA few suggestions... Pin
Scott Dorman24-Jul-08 17:11
professionalScott Dorman24-Jul-08 17:11 
GeneralRe: A few suggestions... Pin
Ravi Bhavnani25-Jul-08 6:38
professionalRavi Bhavnani25-Jul-08 6:38 
GeneralRe: A few suggestions... Pin
Scott Dorman25-Jul-08 14:19
professionalScott Dorman25-Jul-08 14:19 
GeneralRe: A few suggestions... Pin
Ravi Bhavnani25-Jul-08 19:21
professionalRavi Bhavnani25-Jul-08 19:21 
GeneralNot working... Pin
henur22-Jul-08 6:59
memberhenur22-Jul-08 6:59 
Hi
I added the class cueProvider to another project and i do not get it to work.

No errors , just dont have any effect.

I have VS2005 and framwork 3.5

Heino
GeneralRe: Not working... Pin
Ravi Bhavnani22-Jul-08 7:51
professionalRavi Bhavnani22-Jul-08 7:51 
GeneralRe: Not working... Pin
henur22-Jul-08 21:48
memberhenur22-Jul-08 21:48 
GeneralRe: Not working... Pin
Ravi Bhavnani23-Jul-08 6:55
professionalRavi Bhavnani23-Jul-08 6:55 
AnswerRe: Not working... Pin
Ravi Bhavnani24-Jul-08 11:52
professionalRavi Bhavnani24-Jul-08 11:52 
GeneralRe: Not working... Pin
henur26-Jul-08 21:12
memberhenur26-Jul-08 21:12 
GeneralRe: Not working... Pin
Ravi Bhavnani27-Jul-08 7:26
professionalRavi Bhavnani27-Jul-08 7:26 
GeneralRe: Not working... Pin
HunterM21-Aug-08 10:47
memberHunterM21-Aug-08 10:47 
GeneralRe: Not working... Pin
Ravi Bhavnani23-Aug-08 11:35
professionalRavi Bhavnani23-Aug-08 11:35 
GeneralRe: Not working... Pin
HunterM25-Aug-08 7:03
memberHunterM25-Aug-08 7:03 
GeneralRe: Not working... Pin
Ravi Bhavnani25-Aug-08 7:53
professionalRavi Bhavnani25-Aug-08 7:53 
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
memberHiMik200316-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 

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.

Article
Posted 16 Jul 2008

Tagged as

Stats

117.1K views
3.8K downloads
80 bookmarked