Displaying "Type here to ..." until the user enters text into a TextBox
is a well-known usability feature nowadays. How would one implement this feature in C#?
My idea is to override OnTextChanged
, but the logic to handle the changes of text from and to "Type here" is a bit tricky...
Displaying "Type here" on initialization and removing it on first input is easy, but I want to display the message every time the entered text becomes empty.
Based on answer of Ahmed Soliman Flasha use following class:
Based on @Pooven's answer (thank you!), I created this class. Works for me.
Why using OnTextChanged? I would suggest to remove the text "Type here" when the TextBox gets focus. When the control loses focus and no text is entered, you can display the text again.
Same result and no need for tricky logic.
If you want to avoid control resizing problems and data binding problems and make the code simpler (ok, it is questionable), you can just use a label and toggle it's visibility. Then
Another approach for images and also avoiding data binding problems is here https://msdn.microsoft.com/en-us/library/bb613590(v=vs.100).aspx
What you're looking for is a texbox with "watermark"
There's a sample implementation for C# here.
Hope it helps