Group Box grp• Used as containers for other controls such as radio buttons and check – What is displayed on the top edge of the group box Group Group... Check Box chk• Used for user in
Trang 1Chapter 2
More Controls
Programming In
C Shap
Trang 2Controls in the Toolbox
Trang 53 Text Box (txt)
• Used for user input/data entry
– What is displayed in text box
– What user entered in text box
Trang 64 Group Box (grp)
• Used as containers for
other controls such as
radio buttons and check
– What is displayed on the
top edge of the group box Group Group
Trang 75 Check Box (chk)
• Used for user input/data entry
• Allows the user to select or
deselect 1 or more in any group
• Checked Property (stores current
state of the Check Box)
– Checked = True
– Unchecked = False
• CheckChanged Event
– Occurs when user clicks on one of
the Check Boxes
Check box
Trang 86 Radio Button (rad)
• Used for user input/data entry
• Allows the user to select only 1 in any group
• First create a group and then create each
radio button inside the group
• Checked Property (stores current state of
the Radio Button)
• Checked = True
– Unchecked = False
• CheckChanged Event
– Occurs when user clicks on one of the
Trang 97 Picture Box (pic)
– StretchImage causes graphic to
be resized to match the size of
the control
Trang 107 Form (frm) Đặc biệt chứa các
control khác
Common Properties Description
Enter is pressed.
Escape key is pressed.
none, single, dimensional).
Trang 11three-7 Form (frm) Đặc biệt chứa các
control khác (cont)
Common Methods Description
Close() Closes a Form and releases all
resources, such as the memory used for the Form's controls and
components A closed Form cannot be reopened
Show() Displays a hidden Form
Hide() Hides a Form, but does not destroy the
Form or release its resources
Trang 127 Form (frm) Đặc biệt chứa các control khác (cont)
displayed in the Visual Studio editor when you double click the Form in the Visual Studio
designer.
Trang 13Selecting Multiple Controls
• SHIFT-Click or CTRL-Click to
select/deselect multiple controls
• Use the mouse to drag a selection box
around multiple controls
• To deselect all selected controls click
elsewhere on the form
Trang 14Selecting Multiple Controls
Start
here
Drag
to here
Trang 15What Can be Done with
Multiple Selected Controls?
• Use Format Menu or Layout Toolbar to
– Align them to each other
• Move them as a group
• Set their common properties
Trang 16Designing the User Interface
• To the user the Interface should be
– Sans Serif Fonts are best, not boldface or large
Trang 17Keyboard Access Keys
• Also referred to as Hot Keys
• Underlined Letter
• User presses ALT + underlined letter
• Use Windows-Standard Keys
• Defined using Text Property
Text=&OK Text=E&xit
Trang 18Default & Cancel Buttons
– Responds to ESC key
– Form's CancelButton Property
Trang 19Focus
• Not all control types can receive the focus
• TabStop Property (applicable only for controls that are capable of receiving the focus- labels and pictures can’t)
– Designates whether a control is allowed to
receive the focus; True or False
Trang 20Tab Order
focus through a form in an organized manner; top
to bottom, left to right
• TabStop property (yes is the defaualt)
– Number in tab sequence
– 0 for first control to receive the focus when the form
loads
Trang 21Setting TabIndex Property
• View menu, TabOrder
• Click on each control in sequence to set
TabIndex property of controls automatically
Trang 22Form's Screen Location
Trang 23• Small label that is displayed when user places
pointer on a control and pauses
• Usually used with Command Buttons
• Steps for creating ToolTips
– Add a ToolTip Control to Form
• Appears in the Component Tray, pane at bottom of Form
Designer where nondisplay controls are shown
– Set ToolTip on ToolTip1 Property of each control to
the text of tip
Trang 25txtName.Text = ""
lblMessage.Text = ""
txtCourse.Clear( )
Clearing Text Boxes & Labels
– Empty String is 2 quotation marks with no space
between them ("")
Trang 26txtName.Focus( )
Resetting the Focus
• Places the Insertion Point in a Text Box
• Use the Focus Method
Trang 27radRed.Checked = True chkBold.Checked = False
Checked Property of Check Boxes and Radio Buttons
• Selects/Deselects Check Box or Radio
Button
• Set Checked Property
Trang 28C# Color Constants
Class
keyword Color followed by a period
txtName.ForeColor = Color.AliceBlue lblMessage.BackColor = Color.White
Trang 29lblFullName.Text = txtFName.Text + " " & txtLName.Text lblNote.Text = "Today's w eather is " + txtWeather.Text & "."
Concatenation
• Think of it as "glueing" text strings together
• Example: txtFName contains First Name
txtLName contains Last Name
Trang 30private void radgreen_CheckedChanged(object sender, EventArgs e)
{ lblDDang.ForeColor = Color.Green; }
Trang 31Ví Dụ 2 LightSwitcher
picMo picTat
lblhuongdan