TextBox prompt

Sun, June 11, 2006, 06:44 PM under Windows | Vista
I just discovered "prompt" for textboxes (no medal required, thank you :-)).
The inspiration to dig into it was the mention in the Vista guidelines (scroll down to "Prompts").

So, you have empty textboxes and you need to prompt the user to do something and in some cases it makes sense to provide that prompt in the textbox while not making it part of the textbox text/content itself; when the user clicks on the textbox (gives it focus) or enters text into it, the prompt has to dissappear of course.

So if you have a windows form with a button and a textbox that has no text in it, put this code in the button_click event handler method:
new HandleRef(textBox1, textBox1.Handle),
"some prompt. click in the textbox to make me go away"
...and the constants you need are:
internal const uint ECM_FIRST = 0x1500;
internal const uint EM_SETCUEBANNER = ECM_FIRST + 1;
The good news seems to be that this is also available on XP, if we are to believe this msdn link.

It would be nice to have this feature on Windows CE so we could use it in our Windows Mobile applications where screen real estate is at a premium and having additional labels to describe the textbox is sometimes wasteful.
Comments are closed.