Home » C# Basics » 08 - Windows Programming - 1
8

TextBox Control

Defines the properties of the textbox control in a windows application

TextBox control is used to enter the user input. The use can enter text, numbers or special characters in the textbox. The following are the most commonly used properties of the TextBox control:

(Name)

The name used to access the control in code.

Enabled

To decide if the control is enabled or not.

BorderStyle

To set the style of the border.

Text

The text to be displayed in the control.

Visible

To decide if the control is visible or not.

MultiLine

To decide if the control can display multiple lines of text.

BackColor

To set the background color.

ForeColor

To set the foreground color.

ScrollBars

To specify if scrollbars will be displayed in a multi line textbox.

PasswordChar

To specify the character to be used as the password character. The textbox will display this character instead of normal characters entered by the user.

The textbox control has some useful events as listed below:

TextChanged

Occurs when the text in the textbox changes.

KeyDown, KeyUp, KeyPress

The KeyDown and KeyUp events get the code of the key pressed inside the textbox. We can use these events to determine if special keys such as Ctrl, Shift or Function keys were pressed.

The KeyPress event gets the character of the key pressed such as the alphabets or numbers.