65.9K
CodeProject is changing. Read more.
Home

CueProvider

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.79/5 (24 votes)

Jul 17, 2008

CPOL
viewsIcon

156736

downloadIcon

4103

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.