Windows form application Textbox control

  • by

Windows form application Textbox control

A textbox control in C# is used for getting information from the user. You can use it for different functionalities in your form.  It can be single-lined or multi-lined and a normal textbox or a password textbox. 

In your form, take a new Textbox from the toolbox(press Ctrl+W,X or View>Toolbox to open the toolbox) and go into the properties of the textbox. windows form application textbox control 1

Changing the Properties of your Textbox :

You can change ID or name of your textbox by changing the name in the property windows (marked above). Go ahead and change the border style and Font style of your textbox according to you, and run your application to see the effects. Now Change few other properties of this textbox such as make it Multiline textbox :

windows form application textbox control 2

And Of course you can do lots of other things too. Now let’s code our textbox.

Event Handling :

Take a button control in your form and change its text to OK.

windows form application textbox control 3

Double click on it, it will create a event is the code file of your form and these line of code in the file :

windows form application textbox control 4

This will display the text content of our textbox into a Messagebox when user clicks on it.

To get the content of the textbox in string format, write:

String s = TextName.Text.toString();

To get the content of the textbox in integer format, write :

int i = Convert.ToInt32(TextBoxName.Text.ToString());

 


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.