Week 2 Basic Windows Programming
Week 2 Basic Windows Programming
Week 2:
WINDOWS PROGRAMMING
Week 2:
WINDOWS PROGRAMMING
CONTROLS
When you work with Windows Forms, you
are working with the
System.Windows.Forms namespace
Most controls in .NET derive from the
System.Windows.Forms.Control class
Many of these classes are themselves base
classes for other controls, as is the case with
the Label and TextBoxBase classes
1
4/25/2011
CONTROLS
Properties
Common Control Class Properties
Properties
Common Control Class Properties
2
4/25/2011
Adding Controls
Programmatically
1. Create a private variable to represent each
of the controls you want to place on the form
2. In the form, place code to instantiate each
control and to customize each control, using
its properties, methods, or events.
3. Add each control to the forms control
collection.
3
4/25/2011
4
4/25/2011
Naming Rules
Always use standard names for objects
No spaces or punctuation marks
3 letter lowercase prefix identifies control type
Button-btn
Label-lbl
Form-frm
If multiple words capitalize 1st letter of each word
Each object name is an identifier
Can contain letters, digits, and underscores (_)
5
4/25/2011
Recommended Naming
Object Class Prefix Example
Form frm frmDataEntry
Button btn btnExit
TextBox txt txtPaymentAmount
Label lbl lblTotal
Radio Button rad radBold
CheckBox chk chkPrintSummary
PictureBox pic picLandscape
ComboBox cbo cboBookList
ListBox lst lstIndegredients
GroupBox grb grbColor
Windows Forms
Windows Forms is the basic building block of
the UI
It provides a container that hosts controls and
menus and enables you to present an
application in a familiar and consistent
fashion
You can add and configure additional forms
at design time, or you can create instances of
predesigned forms in code at run time.
Windows Forms
Some Properties of the Form Class
6
4/25/2011
Windows Forms
Some Properties of the Form Class
Windows Forms
Some Properties of the Form Class
7
4/25/2011
TopMost = True
FormBorderStyle = False;
StartPosition = CenterToScreen;
8
4/25/2011
9
4/25/2011
Constant distance
to left and top sides
Click down-arrow
in Anchor property
to display
anchoring window
10
4/25/2011
Week 2:
WINDOWS PROGRAMMING
11
4/25/2011
12
4/25/2011
Week 2:
WINDOWS PROGRAMMING
13
4/25/2011
14
4/25/2011
Week 2:
WINDOWS PROGRAMMING
15
4/25/2011
16