Bai1_Basic_Controls
Download
Report
Transcript Bai1_Basic_Controls
WinForms – Basic Controls
1
Objectives
Overview Window Form and
basic Control
Form class
Type of Control
Basic Control
Summary
2
Windows Form
3
WinForms and .NET Framework
4
Features
Create App with leats operation
Store global data to reused
anywhere
ToolStrip,MenuStrip ….
Powerfull way to link control with
data source ( BindingSource
component)
GDI+ : drawing and painting
image on forms
5
Form : basic unit of Application
6
Form : property & method
7
Events
8
Life cycle of a form
Event
• Activated
• Click
• Deactivated
• FormClosed
• FormClosing
• GotFocus
• Load
• Resize
9
Use of Controls
Control class
Base class of all
controls
available in
WinForms
10
Control Class – Properties-Method
Properties
canFocus
Controls
Enable
Name
Parent
TabIndex
Visible
Method
•
•
•
•
•
•
Focus
getNextControl
Hide
IsMNemonic
Select
Show
Event
•
•
•
•
•
•
•
•
•
•
Click
ControlAdd
DoubleClick
Validating
Validated
KeyPress
Leave
LostFocus
MouseClick
Move
11
Common Controls
12
Label class : Property – Method- Event
Properties
Name
Text
TextAlign
UseMnemonic
Method
• Contains
• Hide
• Show
Event
• Click
Label fname = new Label();
fname.Text = “&First Name : “;
fname.UseMnemonic = true ;
13
TextBox & MaskedTextBox
14
TextBox class : Property – Method- Event
Properties
CharacterCasing
MaxLength
MultiLine
Name
PasswordChar
ReadOnly
Text
Method
•
•
•
•
•
AppendText
Clear
Focus
Copy
Paste
Event
• KeyPress
• Leave
• TextChanged
15
MaskedTextBox class :
Property – Method- Event
Properties
Mask
MaskFull
MaskCompleted
Name
PromptChar
Text
Method
• GetPositionFr
omCharIndex
• IsKeyLock
• SelectAll
Event
• MaskChanged
• MaskedInputR
ejected
MaskedTextBox mks = new MaskedTextBox();
mks.Mask = “00000-9999”;
mks.Text = “095204-7763”;
if(!mks.MaskFull)
{
MessageBox.Show(“Enter proper code …”);
}
16
Mask
17
Button class :
Property – Method- Event
Properties
Method
DialogResult
• Focus
Enabled
• PerformClick
FlatStyle
Image
Name
Button cmdOK = new Button();
cmdOK .Text = “OK” ;
Text
Event
• Click
• DoubleClick
• MouseDoubleClick
cmdOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
18
ListBox & ComboBox
ListBox : select
multivalue ( 1..N)
ComboBox : select
one value at a time
19
ListBox class : Property – Method- Event
Properties
DisplayMember
Items
SelectionMode
SelectedIndex
Method
•
•
•
•
ClearSelected
GetItemText
GetSelected
SetSelected
Event
• SelectedIndex
Changed
• SelectedValue
Changed
• ValueMember
Changed
20
ComboBox class :
Property – Method- Event
Properties
Method
DropDownStyle • GetItemText
• SelectAll
Items
MaxDropDownIt • Select ( int start
, int length)
em
SelectedItem
SelectedIndex
Text
ValueMember
Event
• DropDown
• SelectedIndex
Changed
• SelectedValue
Changed
• ValueMember
Changed
21
LinkLabel Control
Display a Hyperlink that
link to a Web Page or
another Window Form
Properties : ActiveLinkColor
, Links , LinkColor ,
LinkVisited, Text ,
VisitedLinkColor
Method : Select
Event : LinkClicked
22
Summary – WorkShop Activities
What is WinForm ?
Focus on Control
TextBox , ListBox , ComBoBox ….
23
Grouping Controls
Value Setting ControlForm class
RadioButton
CheckBox
CheckListBox
Grouping Controls
GroupBox
Panel
Images Control
PictureBox
ImageList
Summary
24
RadioButton Class – PropertiesMethod
Properties
Method
Appearance
AutoCheck
Checked
Image
• PerformClick
• Select
• Show
Event
• CheckedChanged
• Click
25
CheckBox class : Property – Method- Event
Properties
Checked
CheckState
ThreeState
Method
• Select
• Show
Event
• CheckedChanged
• CheckStateChange
• Click
26
CheckedListBox class :
Property – Method- Event
Properties
CheckedIndices
CheckedItems
CheckOnClick
Items
SelectedValue
SelectedItems
SelectedItem
Method
•
•
•
•
•
•
ClearSelected
GetItemChecked
GetItemCheckState
GetItemText
SetItemChecked
SetItemCheckState
Event
• ItemCheck
• MouseClick
• SelectedIndexCh
anged
• SelectedValueCh
anged
27
Grouping Control
Panel
Contains other
Control
GroupBox
As Panel but appear
as Frame around
Control
28
Panel class : Property – Method- Event
Properties
Method
AutoSize
• Select
AutoSizeMode • Show
BorderStyle
Event
• StyleChanged
• VisibleChanged
29
GroupBox : Property – Method- Event
Properties
AutoSize
Anchor
FlatStyle
Method
• Hide
• Show
Event
• StyleChanged
• Resize
30
Graphic Controls
PictureBox
Display image on the
Form ( .bmp ,.jpg ..)
Can hold sigle image
at a time
ImageList
Store collection of
images
31
PictureBox : Property – Method- Event
Properties
Image
ErrorImage
InitialImage
SizeMode
Method
• Load
• LoadAsync
Event
• Click
• Leave
• LoadCompleted
32
ImageList: Property – Method- Event
Properties
Images
ColorDepth
ImageSize
Name
Method
• Draw
Event
• RecreateHandle
33
SplitContainer
Divide the form
into two resizable
panels
As Window
Explorer
•
Properties
•BorderStyle
• FixedPanel
• IsSplitterFixed
• Panel1
• Panel2
• Orientation
Method
•OnSplitterMoved
• OnSplitterMoving
•
Event
•SplitterMoved
• SplitterMoving
• Click
34
Summary – WorkShop Activities
35