1 WinForms – Basic Controls. Objectives Overview Window Form and basic Control Form class Type...

35
1 WinForms – Basic Controls

Transcript of 1 WinForms – Basic Controls. Objectives Overview Window Form and basic Control Form class Type...

Page 1: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

1

WinForms – Basic Controls

Page 2: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Objectives

Overview Window Form and basic Control

Form class Type of Control Basic Control Summary

2

Page 3: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Windows Form

3

Page 4: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

WinForms and .NET Framework

4

Page 5: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Features

5

Create App with leats operation

Store global data to reused anywhere

Powerfull way to link control with data source ( BindingSource

component)

GDI+ : drawing and painting image on forms

ToolStrip,MenuStrip ….

Page 6: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Form : basic unit of Application

6

Page 7: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Form : property & method

7

Page 8: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Events

8

Page 9: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Life cycle of a form

9

Event

• Activated• Click• Deactivated• FormClosed• FormClosing• GotFocus• Load• Resize

Page 10: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Use of Controls

10

Control classBase class of all

controls available in WinForms

Page 11: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

canFocus Controls Enable Name Parent TabIndex Visible

11

Properties

• Focus• getNextControl• Hide• IsMNemonic• Select• Show

Method

• Click• ControlAdd• DoubleClick• Validating• Validated• KeyPress• Leave• LostFocus• MouseClick• Move

Event

Control Class – Properties-Method

Page 12: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Common Controls

12

Page 13: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Label class : Property – Method- Event

NameTextTextAlignUseMnemonic

13

Properties

• Contains• Hide• Show

Method

• Click

Event

Label fname = new Label();fname.Text = “&First Name : “;fname.UseMnemonic = true ;

Page 14: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

TextBox & MaskedTextBox

14

Page 15: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

TextBox class : Property – Method- Event

CharacterCasing MaxLength MultiLine Name PasswordChar ReadOnly Text

15

Properties

• AppendText• Clear• Focus• Copy• Paste

Method

• KeyPress• Leave• TextChanged

Event

Page 16: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

MaskedTextBox class : Property – Method- Event

Mask MaskFull MaskCompleted Name PromptChar Text

16

Properties

• GetPositionFromCharIndex

• IsKeyLock• SelectAll

Method

• MaskChanged• MaskedInputR

ejected

Event

MaskedTextBox mks = new MaskedTextBox();mks.Mask = “00000-9999”;mks.Text = “095204-7763”;if(!mks.MaskFull){

MessageBox.Show(“Enter proper code …”);}

Page 17: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Mask

17

Page 18: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Button class : Property – Method- Event

DialogResult Enabled FlatStyle Image Name Text

18

Properties

• Focus• PerformClick

Method

• Click• DoubleClick• MouseDoubleClick

Event

Button cmdOK = new Button();cmdOK .Text = “OK” ; cmdOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

Page 19: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

ListBox & ComboBox

19

ListBox : select multivalue ( 1..N)

ComboBox : select one value at a time

Page 20: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

ListBox class : Property – Method- Event

DisplayMember Items SelectionMode SelectedIndex

20

Properties

• ClearSelected• GetItemText• GetSelected• SetSelected

Method

• SelectedIndexChanged

• SelectedValueChanged

• ValueMemberChanged

Event

Page 21: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

ComboBox class : Property – Method- Event

DropDownStyle ItemsMaxDropDownItemSelectedItemSelectedIndexTextValueMember

21

Properties

• GetItemText• SelectAll• Select ( int start

, int length)

Method

• DropDown• SelectedIndex

Changed• SelectedValue

Changed• ValueMember

Changed

Event

Page 22: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

LinkLabel Control

22

Display a Hyperlink that link to a Web Page or another Window Form

Properties : ActiveLinkColor , Links , LinkColor , LinkVisited, Text , VisitedLinkColor

Method : Select

Event : LinkClicked

Page 23: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Summary – WorkShop Activities

What is WinForm ? Focus on Control TextBox , ListBox , ComBoBox ….

23

Page 24: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Grouping Controls

Value Setting ControlForm class RadioButton CheckBox CheckListBox

Grouping Controls GroupBox Panel

Images Control PictureBox ImageList

Summary

24

Page 25: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Appearance AutoCheck Checked Image

25

Properties

• PerformClick• Select• Show

Method

• CheckedChanged• Click

Event

RadioButton Class – Properties-Method

Page 26: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

CheckBox class : Property – Method- Event

CheckedCheckStateThreeState

26

Properties

• Select• Show

Method

• CheckedChanged• CheckStateChange• Click

Event

Page 27: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

CheckedListBox class : Property – Method- Event

CheckedIndices CheckedItems CheckOnClick Items SelectedValue SelectedItems SelectedItem

27

Properties

• ClearSelected• GetItemChecked• GetItemCheckState• GetItemText• SetItemChecked• SetItemCheckState

Method

• ItemCheck• MouseClick• SelectedIndexCh

anged• SelectedValueCh

anged

Event

Page 28: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Grouping Control

Panel Contains other

Control GroupBox

As Panel but appear as Frame around Control

28

Page 29: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Panel class : Property – Method- Event

AutoSizeAutoSizeModeBorderStyle

29

Properties

• Select• Show

Method

• StyleChanged• VisibleChanged

Event

Page 30: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

GroupBox : Property – Method- Event

AutoSizeAnchorFlatStyle

30

Properties

• Hide• Show

Method

• StyleChanged• Resize

Event

Page 31: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Graphic Controls

PictureBox Display image on the

Form ( .bmp ,.jpg ..) Can hold sigle image

at a time ImageList

Store collection of images

31

Page 32: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

PictureBox : Property – Method- Event

ImageErrorImage InitialImageSizeMode

32

Properties

• Load• LoadAsync

Method

• Click• Leave• LoadCompleted

Event

Page 33: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

ImageList: Property – Method- Event

ImagesColorDepth ImageSizeName

33

Properties

• Draw

Method

• RecreateHandle

Event

Page 34: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

SplitContainer

Divide the form into two resizable panels

As Window Explorer

34

• Properties •BorderStyle• FixedPanel• IsSplitterFixed• Panel1• Panel2• Orientation

Method •OnSplitterMoved• OnSplitterMoving

• Event•SplitterMoved• SplitterMoving• Click

Page 35: 1 WinForms – Basic Controls. Objectives  Overview Window Form and basic Control  Form class  Type of Control  Basic Control  Summary 2.

Summary – WorkShop Activities

35