0

I am trying to make a form where I can get a specific value from the user and save it in a table. This table is visible to the user at the same time. The form I made shows the table using a datagridview. The value I need to enter is being taken by the inputbox. (I referred this site).

The problem is that, the value being taken by the inputbox follows a certain syntax, and I need to inform this to the user, I have thought of showing the syntax in the textbox, and when the user selects the textbox to enter this value the preloaded text is removed.

Brian
  • 5,069
  • 7
  • 37
  • 47
  • 2
    Is there a question in there? – Sam Axe Apr 25 '13 at 18:32
  • The term you're looking for is 'placeholder', see [Adding placeholder text to textbox](http://stackoverflow.com/questions/11873378/adding-placeholder-text-to-textbox). – CodeCaster Apr 25 '13 at 18:38
  • 2
    @CodeCaster: Alternatively, some people refer to it as a 'watermark', see http://stackoverflow.com/a/2487119/347172. – myermian Apr 25 '13 at 18:49

4 Answers4

1

You can use the MaskedTextbox instead of the classic TextBox:

http://msdn.microsoft.com/de-de/library/system.windows.forms.maskedtextbox.mask(v=vs.110).aspx

Kai
  • 1,953
  • 2
  • 13
  • 18
1

To add to what Kai said, you can also use the ErrorProvider class to provide notifications to the user if the input provided does not validate.

http://msdn.microsoft.com/en-us/library/system.windows.forms.errorprovider.aspx http://www.codeproject.com/Articles/898/How-To-Use-The-ErrorProvider-Object-To-Indicate-In

tobyb
  • 696
  • 9
  • 18
1

You should consider using a MaskedTextBox.

A simple implementation would look like this:

MaskedTextBox mskTxtBox = new MaskedTextBox();
mskTxtBox.Mask = /* format your Mask here */;

A further - and more specific example - would be:

mskTxtBox.Mask = "(123)456-7890"; //For a phone number.

Or:

mskTxtBox.Mask = "00/00/0000"; //For a date.
Brian
  • 5,069
  • 7
  • 37
  • 47
0

This is not standard .Net, it's more Vb.Net stuff as this class is part of Microsoft.VisualBasic assembly. I recommend you to switch to MaskedTextBox instead, in the standard System.Windows.Forms namespace.

http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx

Oscar
  • 13,594
  • 8
  • 47
  • 75