2002 Prentice Hall. All Rights Reserved
2002 Prentice Hall. All Rights Reserved
12.1 Introduction
Button Label Menu Bar TextBox Scrollbar
12.1 Introduction
TextBox An area in which the user inputs data from the keyboard. The area also
can display information.
Button An area that triggers an event when clicked.
CheckBox A GUI control that is either selected or not selected.
ComboBox A drop-down list of items from which the user can make a selection,
by clicking an item in the list or by typing into the box, if permitted.
ListBox An area in which a list of items is displayed from which the user can
make a selection by clicking once on any element. Multiple elements
can be selected.
Panel A container in which components can be placed.
ScrollBar Allows the user to access a range of values that cannot normally fit in
its container.
Fig . 12.2 So m e b a sic G UI c o m p o n e n ts.
Events icon
List of events
supported by
control
Selected event
Current even
handler (none)
Event
description
SimpleEventExamp
le.cs
Program Output
Event name
Constant distance to
left and top sides
Click down-arrow
in Anchor property
to display
anchoring window
C o m m o n La yo ut De sc rip tio n
Pro p e rtie s
Common Properties
Anchor Side of parent container at which to anchor control—values can be
combined, such as Top, Left.
Dock Side of parent container to dock control—values cannot be combined.
DockPadding (for Sets the dock spacing for controls inside the container. Default is zero,
containers) so controls appear flush against the side of the container.
Location Location of the upper-left corner of the control, relative to it’s
container.
Size Size of the control. Takes a Size structure, which has properties
Height and Width.
MinimumSize, The minimum and maximum size of the form.
MaximumSize (for
Windows Forms)
Fig . 12.14 C la ss Control la yo u t p ro p e rtie s.
AcceptsReturn If true, pressing Enter creates a new line if textbox spans multiple
lines. If false, pressing Enter clicks the default button of the form.
Multiline If true, textbox can span multiple lines. Default is false.
PasswordChar Single character to display instead of typed text, making the
TextBox a password box. If no character is specified, Textbox
displays the typed text.
ReadOnly If true, TextBox has a gray background and its text cannot be
edited. Default is false.
ScrollBars For multiline textboxes, indicates which scrollbars appear (none,
horizontal, vertical or both).
Text The text to be displayed in the text box.
Common Events (Delegate EventHandler, event arguments EventArgs)
TextChanged Raised when text changes in TextBox (the user added or deleted
characters). Default event when this control is double clicked in the
designer.
Fig . 12.16 TextBox p ro p e rtie s a n d e ve n ts.
Program Output
AutoScroll Whether scrollbars appear when the Panel is too small to hold its
controls. Default is false.
BorderStyle Border of the Panel (default None; other options are Fixed3D and
FixedSingle).
Controls The controls that the Panel contains.
Fig . 12.20 Panel p ro p e rtie s.
Controls inside
panel panel
panel
scrollbars
GroupBoxPanelExa
mple.cs
Program Output
CheckBoxTest.cs
Program Output
RadioButtonsTest
.cs
Program Output
RadioButtonsTest
Information icon type Question icon type .cs
Program Output
12.8 PictureBoxes
Program Output
Mo u se Eve n ts, De le g a te s
a n d Eve n t Arg u m e n ts
Mouse Events (Delegate
EventHandler, event
arguments EventArgs)
MouseEnter Raised if the mouse cursor enters the area of the control.
MouseLeave Raised if the mouse cursor leaves the area of the control.
Mouse Events (Delegate
MouseEventHandler,
event arguments
MouseEventArgs)
MouseDown Raised if the mouse button is pressed while its cursor is over the area of the
control.
MouseHover Raised if the mouse cursor hovers over the area of the control.
MouseMove Raised if the mouse cursor is moved while in the area of the control.
MouseUp Raised if the mouse button is released when the cursor is over the area of the
control.
Class MouseEventArgs
Properties
Button Mouse button that was pressed (left, right, middle or none).
Clicks The number of times the mouse button was clicked.
X The x-coordinate of the event, relative to the component.
Y The y-coordinate of the event, relative to the component.
Fig . 12.29 Mo u se e ve n ts, d e le g a te s a n d e ve n t a rg u m e n ts.
Program Output
KeyDemo.cs
Program Output