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

Preview:

Citation preview

1

WinForms – Basic Controls

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

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 ….

Form : basic unit of Application

6

Form : property & method

7

Events

8

Life cycle of a form

9

Event

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

Use of Controls

10

Control classBase class of all

controls available in WinForms

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

Common Controls

12

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 ;

TextBox & MaskedTextBox

14

TextBox class : Property – Method- Event

CharacterCasing MaxLength MultiLine Name PasswordChar ReadOnly Text

15

Properties

• AppendText• Clear• Focus• Copy• Paste

Method

• KeyPress• Leave• TextChanged

Event

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 …”);}

Mask

17

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;

ListBox & ComboBox

19

ListBox : select multivalue ( 1..N)

ComboBox : select one value at a time

ListBox class : Property – Method- Event

DisplayMember Items SelectionMode SelectedIndex

20

Properties

• ClearSelected• GetItemText• GetSelected• SetSelected

Method

• SelectedIndexChanged

• SelectedValueChanged

• ValueMemberChanged

Event

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

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

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

Appearance AutoCheck Checked Image

25

Properties

• PerformClick• Select• Show

Method

• CheckedChanged• Click

Event

RadioButton Class – Properties-Method

CheckBox class : Property – Method- Event

CheckedCheckStateThreeState

26

Properties

• Select• Show

Method

• CheckedChanged• CheckStateChange• Click

Event

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

Grouping Control

Panel Contains other

Control GroupBox

As Panel but appear as Frame around Control

28

Panel class : Property – Method- Event

AutoSizeAutoSizeModeBorderStyle

29

Properties

• Select• Show

Method

• StyleChanged• VisibleChanged

Event

GroupBox : Property – Method- Event

AutoSizeAnchorFlatStyle

30

Properties

• Hide• Show

Method

• StyleChanged• Resize

Event

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

ImageErrorImage InitialImageSizeMode

32

Properties

• Load• LoadAsync

Method

• Click• Leave• LoadCompleted

Event

ImageList: Property – Method- Event

ImagesColorDepth ImageSizeName

33

Properties

• Draw

Method

• RecreateHandle

Event

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

Summary – WorkShop Activities

35

Recommended