C# Chapter 2
C# Chapter 2
C# Chapter 2
Chapter 2
Introducing Controls
Introducing Controls
Labels
Label controls are typically used to provide
descriptive text for a control.
Text Boxes
Use a text box control when you want the user to
type some input.
Text Boxes
You can use the Text property of each text
box.
Clearing Text Boxes and Labels
You can clear out the contents of a text box or
label by setting the property to an empty string .
Use "" (no space between the two quotation
marks). This empty string is also called a null
string or zero-length string .
You also can clear out a text box using the Clear
method.
Masked Text Boxes
A specialized form of the TextBox control is the
MaskedTextBox .
You can specify the format (the Mask property) of
the data required of the user.
For example, you can select a mask for a ZIP
code, a date, a phone number, or a social security
number.
Input mask for Masked Text Boxes
Rich Text Boxes
RichTextBox offers several formatting features
(the user can apply character and paragraph
formatting to selected text, much like using a word
processor)
Check Boxes
Check boxes allow the user to select (or deselect) an
option. In any group of check boxes, any number can be
selected.
The Checked property of a check box is set to false if
unchecked or true if checked. You can write an event
handler for the CheckedChanged event, which executes
when the user clicks in the box.
Check Box
Radio Buttons
Use radio buttons when only one button of a group may be
selected.
A group of radio buttons inside a group box function
together.
The best method is to first create a group box and then create
each radio button inside the group box.
The Checked property of a radio button is set to true if
selected or to false if unselected.
You can write an event handler to execute when the user
selects a radio button using the control’s CheckedChanged
event
Radio Buttons with Group box
Combo Box
Picture Boxes
A PictureBox control can hold an image. You can set a
picture box’s Image property to a graphic file with an
extension of .bmp, .gif, .jpg, .jpeg, .png, .ico, .emf,
or .wmf.
You first add your images to the project’s resources; then
you can assign the resource to the Image property of a
PictureBox control.
Picture Boxes properties
Picture Boxes manipulation
Assigning an Image to a Picture Box by C# code