JuBull09
JuBull09

Reputation: 1

How to work on the textbox of inputbox using C#?

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.

Upvotes: 0

Views: 167

Answers (4)

Brian
Brian

Reputation: 5119

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.

Upvotes: 1

tobyb
tobyb

Reputation: 746

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

Upvotes: 1

Oscar
Oscar

Reputation: 13960

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

Upvotes: 0

Kai
Kai

Reputation: 2013

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

Upvotes: 1

Related Questions