Click here to Skip to main content
Licence CPOL
First Posted 16 Jul 2008
Views 44,966
Downloads 460
Bookmarked 57 times

CueProvider

By Ravi Bhavnani | 24 Jul 2008
A lightweight class that lets you add cues to a TextBox.

1
1 vote, 5.0%
2
1 vote, 5.0%
3
5 votes, 25.0%
4
13 votes, 65.0%
5
4.77/5 - 20 votes
2 removed
μ 4.55, σa 1.47 [?]

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)

About the Author

Ravi Bhavnani

Software Developer (Senior)

Canada Canada

Member
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, CHI 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 2 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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionDoes not work when textbox is multiline enabled PinmemberMember 11939699:40 17 Sep '11  
AnswerRe: Does not work when textbox is multiline enabled PinmemberRavi Bhavnani9:41 17 Sep '11  
QuestionImplementing with DevExpress.XtraEditors.TextEdit PinmemberBrian, The IT Guy7:45 15 Jun '11  
AnswerRe: Implementing with DevExpress.XtraEditors.TextEdit PinmemberRavi Bhavnani8:03 15 Jun '11  
QuestionCan it work with readonly controls? PinmemberLiko7218:26 25 Feb '11  
AnswerRe: Can it work with readonly controls? PinmemberRavi Bhavnani5:56 26 Feb '11  
GeneralCueProvider and MaskedTextBox Pinmemberzonextrem4:47 12 Aug '08  
GeneralRe: CueProvider and MaskedTextBox PinmemberRavi Bhavnani9:16 12 Aug '08  
GeneralRe: CueProvider and MaskedTextBox Pinmemberzonextrem9:19 12 Aug '08  
The cue is setted only if the maskedtextbox has not a mask.
 
Martin

GeneralRe: CueProvider and MaskedTextBox PinmemberRavi Bhavnani9:22 12 Aug '08  
GeneralDemo not working :( Pinmemberbaruchl23:22 28 Jul '08  
AnswerRe: Demo not working :( PinmemberRavi Bhavnani2:46 29 Jul '08  
GeneralRe: Demo not working :( PinmemberTobiasP4:41 30 Jul '08  
GeneralRe: Demo not working :( PinmemberRavi Bhavnani4:48 30 Jul '08  
GeneralNot working!!! PinmemberQing Jiang5:52 25 Jul '08  
GeneralRe: Not working!!! PinmemberRavi Bhavnani7:39 25 Jul '08  
Generalnot workin Pinmemberpro.rakesh0:58 25 Jul '08  
GeneralRe: not workin PinmemberRavi Bhavnani7:40 25 Jul '08  
GeneralI modified it to do an IExtenderProvider component [modified] PinmemberFabrice CARUSO21:11 24 Jul '08  
GeneralRe: I modified it to do an IExtenderProvider component PinmemberRavi Bhavnani7:39 25 Jul '08  
GeneralA few suggestions... PinmvpScott Dorman18:11 24 Jul '08  
GeneralRe: A few suggestions... PinmemberRavi Bhavnani7:38 25 Jul '08  
GeneralRe: A few suggestions... PinmvpScott Dorman15:19 25 Jul '08  
GeneralRe: A few suggestions... PinmemberRavi Bhavnani20:21 25 Jul '08  
GeneralNot working... Pinmemberhenur7:59 22 Jul '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 24 Jul 2008
Article Copyright 2008 by Ravi Bhavnani
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid