Title: Working with WinForms
1Chapter 2
Working with WinForms
2Objectives
- Explain the concept of properties and events
- Explain the event handling concepts
- Work with basic interface components
3Application
Application
User Interface
4Introduction to Class Libraries
- .Net Framework is based on OO approach.
- Class library is a collection of reusable
classes or types.
- Class libraries are divided into namespaces.
- Namespaces group classes according to their
common services.
Example System.Windows.forms
5Properties and Methods
Class
Frog
Object
Instance of the class
Height Weight Name
properties
Height 12 cm Weight 100gm Name Jumpie
method
Jump
6Events and Event Handlers
- The interaction between various objects
within the application, and between the
objects and external entities is facilitated
through Events and Event Handlers.
EVENT HANDLING
Event handler
Event
7Event Handling Example
Event
When Save Clicked() Display Message(Save
Button) When Print Clicked() Display
Message(Print Button)
Event Handler
User Interface
User action clicking the button
8User Interfaces
Features of good user interfaces
- Easy to learn
- Easy to use
- Attractive
Type of user interfaces
Character based
GUI based
9Windows Application
The basic unit is a form
Uses of a Form ???
- Presents information to the user
- Receives information from the user
An application can have multiple forms
10WinForms GUI (1)
- Form is represented as a class in WinForms.
-
- Whenever an application is created, a form is
added.
- WinForms create an instance of the Form class.
- In WinForms, properties and methods of the
classes are classified as shared and instance - types.
11WinForms GUI (2)
- Shared properties deal with multiple instances of
the same class.
- Instance properties are assigned for each
instance of the class.
- Properties and methods of the form can be
set or read in any of the following ways
WindowsApplication1.Form1.EnabledTrue
Form1.EnabledTrue
12Form Properties, Methods and Events
13Controls
- Form object has many Visual Interface Components.
- Visual Interface Components are collectively
known as Controls.
Example textBox1.EnabledTrue this.textBox1.Enabl
edTrue
14Some Common Properties of Controls
15Different Controls
16Label
PROPERTIES
Methods
Image
Hide
Show
TabStop
Update
Events
Paint
17TextBox
Methods
PROPERTIES
AcceptReturn
AppendText
Clear
ReadOnly
Paste
Passwordchar
Cut
MaxLength
Events
Copy
Multiline
TextChanged
ScrollBars
MultilineChanged
18Button
PROPERTIES
Methods
DialogResult
PerformClick
TextAlign
Events
Click
19ListBox 1
PROPERTIES
Items
SelectedItems
MultiColumn
Sorted
SelectedIndex
SelectedValue
SelectedItem
Text
20ListBox 2
Events
Methods
ClearSelected
SelectedIndexChanged
GetSelected
SelectedValueChanged
FindString
SetSelected
21CheckedListBox
PROPERTIES
Methods
SetItemChecked
CheckedIndices
GetItemChecked
ThreeDCheckBoxes
GetItemCheckState
CheckedItems
Events
SetItemCheckState
ItemCheck
22ComboBox
Methods
PROPERTIES
Select
DropDownStyle
SelectAll
Focused
MaxDropDownItems
Events
DropDown
23Some Form Components
- Identify the control components
24The this keyword
- Represents the current active form.
- All properties, methods, events of the form can
be accessed.
Example this.controlname.propertyname