I have a C# Winforms program with multiple textboxes. I used the properties for each box to place text in them, explaining to the user what value goes in them. I want the text to highlight whenever a user selects that box. By either tabbing or mouse click. I won't have to do this if there's a way to display what value goes in the textbox somewhere outside of it.
I tried the Textbox.select method but it had no effect. The same with this.
Here's a Screenshot of my program.
My Code:
private void grapplingText1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
grapplingText1.SelectionStart = 0;
grapplingText1.SelectionLength = grapplingText1.Text.Length;
Will this do, or is more required?
Best Answer
How about you assign
ToolTip
toTextBox
and put all the "talk what textbox is for" inside that?Just drag & drop
ToolTip
inside the Form. And then in eachTextBox
properties you should have additional entry in Misc sectionToolTip
ontoolTip1
(or whatever it's name will be if you rename it).Then when user hovers over
TextBox
(Read Only/DisabledTextBox
doesn't seems to display ToolTips) and stops there for 1 second ToolTip should show with proper info.You can eventually or even better have a
Label
next toTextBox
saying what is is, but having aToolTip
is also a good idea to explain more information to user thru that.For doing stuff with WaterMark so you don't have to go the long way by setting the events, taking care of SelectAll etc you could do it like this. Create new watermark.cs file and replace it with this code. Make sure you have changed namespace to match your program namespace.
In your Form you activate it like this:
It stays there as long the
TextBox
is empty. When users gets intoTextBox
text disappears. It appears again whenTextBox
is cleaned (either by user or automatically). No need for any special events etc.EDIT:
I've added also internal class WaterMarkTextBox which gives you an option to simply use new WaterMarkTexBox that becomes available in Designer. Then drag and drop it to your designer and use it. It behaves like normal textbox just gives you additional field WaterMarkText.
I still prefer the first method thou. Doesn't make you rebuild your gui again.