Lecture6-CS6004 Application Development
Lecture6-CS6004 Application Development
Application
Development
Lecture 6
Chamila Karunatilake
itchamila@gmail.com
1
Outline
2
First Windows Forms Application
Form
Text Box
Label
List Box
Button
3
Form Control
5
Form Control
7
Set Properties of label1 and
label2
8
Set Properties of button1 and
listBox1
9
Naming Controls
• By default, the names are given to the controls as textBox1, textBox2
and so on.
• However, it is difficult to identify the control and its purpose by looking
at those names.
• Therefore, It is recommended to change them to meaningful names
specifying its purpose in the application
textBox1 txtName
You can change them on the
textBox2 txtAge properties window or in the
source code
Button1 btnAdd
10
Naming Controls
11
Add Events and Event Handlers
• After stabilizing the initial design and naming, the events can be added
to the controls.
• In the example, one of the main event would be clicking the add button.
• To initiate a click event to any control, you can simply double click on the
control.
• Then, click event will be automatically integrated to the control.
• With the event, an event handler method should also be added, which is
executed when the event is occurred.
• This event handler method will also be added automatically in the
Form.cs file (the other partial class of the Form), while event is initiated.
12
Add Events and Event Handlers
Properties Window
Form1.Designer.cs
13
Add Events and Event Handlers
Form1.cs
Event Handler
Method
14
Event Handler Method
15
Event Handler Method
16