Bai1_Basic_Controls

advertisement

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

Event

• Activated

• Click

• Deactivated

• FormClosed

• FormClosing

• GotFocus

• Load

• Resize

Life cycle of a form

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 Method

 Name

 Text

 TextAlign

 UseMnemonic

• Contains

• Hide

• Show

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

Event

• Click

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 Method Event

 Mask

 MaskFull

 MaskCompleted

 Name

 PromptChar

 Text

• GetPositionFr omCharIndex

• IsKeyLock

• SelectAll

• 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 Event

 DialogResult

 Enabled

 FlatStyle

 Image

 Name

 Text

• Focus

• PerformClick

• Click

• DoubleClick

• MouseDoubleClick

Button cmdOK = new Button(); cmdOK .Text = “OK” ; 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

 Items

 MaxDropDownIt em

 SelectedItem

 SelectedIndex

 Text

 ValueMember

• GetItemText

• SelectAll

• Select ( int start

, int length)

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 – Properties-

Method

Properties

 Appearance

 AutoCheck

 Checked

 Image

Method

• PerformClick

• Select

• Show

Event

• CheckedChanged

• Click

25

CheckBox class : Property – Method- Event

Properties

 Checked

 CheckState

 ThreeState

Method

• Select

• Show

Event

• CheckedChanged

• CheckStateChange

• Click

26

Properties

 CheckedIndices

 CheckedItems

 CheckOnClick

 Items

 SelectedValue

 SelectedItems

 SelectedItem

CheckedListBox class :

Property – Method- Event

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

 AutoSizeMode

 BorderStyle

• Select

• Show

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

Download