Vs CS Ch1.2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

MaxLength Get or set the maximum number of characters

that a user can type in the text box control.


MultiLine Get or set a value that indicates whether the
text box can contain multi-line text.
PasswordChar Get or set character to disguise password
characters in a one-line TextBox control.
ReadOnly Get or set a value that indicates whether the
text in the text box control is read-only.
ScrollBars Get or set which scroll bars are displayed
without the multi-line text box control.
SelectedText Get or set a value that indicates the text being
selected.
SelectionLength Get or set how many characters that are
selected in the text box.
SelectionStart Get or set the starting point of the selected text
in the text box.
Tag Stores a string expression.
Text Get or set the current text in the text box.
TextAlign Get or set text alignment on text box.
TextLength Get the length of the text in the text box.

Table 1.13 A number of methods of the TextBox object


AppendText Append text to currentvtext in the text box.
Clear Clear all text in the text box.
Copy Copy selected text to the clipboard.
Cut Move selected text to the clipboard.
Focus Put the cursor on the specified text box.
Paste Replace the current selection in the text box
with the content of the Clipboard.
SelectAll Select all text in the text box.
Undo Cancel the last edit operation of the text box.
Table 1.14 A number of Events from the TextBox object
Click Occurs when the user clicks on the text box.
Enter Occurs when the control receives focus.
KeyDown Occurs when a key is pressed when the control
has focus.
KeyPress Occurs when a key is pressed when the control
has focus.
Leave Triggered when the user leaves the text box.
This is a way to check the content of a text
box when editing the text box is done.
TextChanged Occurs when the value of the Text property
has changed.

General uses of the TextBox control as a viewer control:


Set the Name property. Initialize the Text property with the
desired string.
Set the ReadOnly property to True .
If used to display text more than one line, set the MultiLine
property to True .
You can also change the Font , BackColor , and ForeColor
properties.

General uses of TextBox control as input device:


Set the Name property. Initialize the Text property with the
desired string.
If used to display text more than one line, set the MultiLine
property to True .
In the code, give Focus to the control when needed.
Provide the key entrapment code for the KeyPress event that
will be discussed in this chapter.
Read the Text property when the Leave event occurs.
You can also change the Font , BackColor , and ForeColor
properties.

CheckBox
Visual C# has many controls that give users many choices just by
clicking the mouse. These controls are attractive, familiar, and
minimize the possibility of errors in your application. You will use
a lot of these controls.

CheckBox control provides a way to provide a selection of a


number of potential choices. CheckBox is used in many Windows
applications.

Table 1.15 A number of properties of the CheckBox object


Name Get or set the name of the check box.
BackColor Get or set the background color from the
check box.
Checked Get or set a value indicating whether the check
box is checked.
Font Get or set font name, style, and size.
ForeColor Get or set the color of text or graphics.
Text Get or set the string displayed next to the
check box.
TextAlign Get or set text alignment in the checkbox.

Table 1.16 One of methods of CheckBox object


Focus Move focus to a specific check box.

Table 1.17 A number of Events of the CheckBox object


CheckedChanged Occurs when the value of the Checked
property changes, whether via code or when
the check box is clicked.
Click Triggered when a check box is clicked. The
Checked property is automatically changed by
Visual C#.

When a check box is clicked, if there is no check mark there (


Checked = False ), then Visual C# will place a check mark there
and set Checked property to True . If clicked and previously there
was a check mark there ( Checked = True ), then the check mark
will disappear and Checked property will be changed to Flase .

General uses of CheckBox control:


Set the Name and Text properties.
Initialize the Checked property.
Monitor the Click or CheckChanged event to determine
whether the check box is checked.
Change Font , BackColor , and ForeColor properties.

RadioButton
RadioButton control provides the capability to make mutually
exclusive choices from a number of candidate choices. This means
that the radio button works as a group, only one button can be
selected. The radio button is widely used in Windows applications.
Named as a radio button because it looks similar to a button on a
transistor radio.

Following are a number of properties, methods, and events of the


RadioButton control:

Table 1.18 A number of Properties of the RadioButton object


Name Get or set the name of the radio button.
BackColor Get or set the background color from the radio
button.
Checked Get or set a value indicating whether the radio
button is selected.
Font Get or set font name, style, and size.
ForeColor Get or set the color of text or graphics.
TextAlign Get or set text alignment on radio buttons.

Table 1.19 A number of Methods of the RadioButton object


Focus Move focus to the specified radio button.
PerformClick Generates a Click event for a particular radio
button, by simulating a click by the user.

Table 1.20 A number of Events of the RadioButton object


CheckedChanged Occurs when the value of the Checked
property changes, whether via a code or when
the radio button is clicked.
Click Triggered when a radio button is clicked. The
Checked property is automatically changed by
Visual C#.

General uses of RadioButton control:


Create a radio button group.
For each button in a group, set the Name and Text properties.
Initialize the Checked property.
Monitor the Click or CheckChanged event on each radio
button to determine which radio button is clicked.

GroupBox
You already knew that check boxes and radio buttons work in a
group. The GroupBox control provides a way to group related
controls in a Visual C# application.

To place controls in a group box, you first need to drag or place


GroupBox control into the form. Then, place each control into the
group box.

The group box affects how the radio button works. The radio
buttons on a GroupBox control work as a group, and are not
related to the radio buttons on other GroupBox controls.

Table 1.21 A number of Properties of the GroupBox object


Name Get or set the name of the group box.
Enabled Get or set a value indicating whether the group
box is enabled. If it is False , then all controls
in the group box will be disabled.
BackColor Get or set the background color from the
group box.
Font Get or set font name, style, and size.
ForeColor Get or set color of text.
Text Get or set the string to be displayed in the title
section of the group box.
Visible If it is False , it will hide the group box (and
all the controls it contains).

The GroupBox control has a number of methods and events, but


all of them are rarely used. You will focus more on the methods
and events associated with the controls in the group box.

General uses of GroupBox control:


Set Text and Name properties.
Place the desired controls in the group box.
Monitor the events of each control in the group box.
PictureBox
Visual C# offers a number of features for graphics. The
PictureBox control is one of the main tools in exploiting these
features. The picture box control can display graphic files (with
various formats) and it can utilize a number of graphic functions
and can be used for animation.

Table 1.22 A number of Properties of the PictureBox object


Name Get or set the name of the picture box.
BackColor Get or set the background color from the picture
box.
BorderStyle Indicate the edge style for the picture box.
Height Heighy of the picture box in pixels.
Image Set the graphic file to display in the picture box.
Left The distance from the left edge of the form to
the left edge of the picture box, in pixels.
SizeMode Indicats how the picture is displayed.
Top Lower edge distance from the area of the form
title to the top edge of the picture box, in pixels.
Width Width of the picture box in pixels.

Table 1.23 One of Events of the PictureBox object


Click Triggered when a picture box is clicked.

The Image property specifies the graphic file to be displayed. The


five types of graphics files that can be placed in the image box are
as follows:

Table 1.24 A number of acceptable graphic file types of


PictureBox control
Bitmap An image is represented by pixels and stored as
a collection that contains bits. This is the format
most commonly used by scanner and paintbrush
programs. Format has a .bmp extension.
Icon A special type of bitmap file with a maximum
size of 32 x 32 pixels. This format has the .ico
extension. The icon is used to represent
Windows applications.
Metafile A file that stores an image as a collection that
contains graphical objects (lines, circles,
polygons), not pixels. Metafile has a more
accurate resolution than bitmaps when the size
is enlarged or reduced. This format has a .wmf
extension.
JPEG JPEG (Joint Photographic Experts Group) is a
compressed BMP format that supports 8 bits
and 24 bit colors. This format is popular on the
Internet and is a common format for digital
cameras. JPEG format has the extension .jpg.
GIF GIF (Graphic Interchange Format) is a
compressed bmp format originally developed by
CompuServe. This format supports up to 256 bit
colors and is also popular on the Internet. This
format has a .gif extension.

The SizeMode property states how a particular image will be


displayed. There are five values that can be given to this property:
Normal , CenterImage , StretchImage , AutoSize , and Zoom .
The effect of each of these values is as follows:

Value of SizeMode Effect


Normal The image is displayed at the initial size. If the
picture box is larger than the image, there will
be free space. If the picture box is smaller than
the image, the image will be truncated.
CenterImage The image is displayed at its initial size,
centered on the picture box. If the picture box is
larger than the image, there will be free space. If
the picture box is smaller than the image, the
image will be truncated.
StretchImage The image will 'fill' the picture box. If the image
is smaller than the picture box, the image will
expand. If the image is larger than the picture
box, the image will shrink.
AutoSize The opposite of StretchImage . The picture box
will change its dimensions to adjust the initial
size of the image.
Zoom Same with StretchImage . The image will
adjust so it can be loaded in the picture box.

Note that the dimensions remain unchanged for the Normal ,


CenterImage , StretchImage , and Zoom values. With AutoSize ,
the picture box will change size. This causes problems when the
program runs if your form is not large enough to load the picture
box.

General uses of the PicureBox control in displaying images:


Set the Name and SizeMode properties (often with a
StretchImage value).
Specifiy the Image property, both at the time of design and
when the program runs (run-time).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy