WinForms – Basic Controls
Objectives Overview Window Form and basic Control Form class Type of Control Basic Control Summary
Windows Form
WinForms and .NET Framework
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
Form : basic unit of Application
Form : property & method
Events
Life cycle of a form Event Click Deactivated FormClosed FormClosing GotFocus Load Resize
Base class of all controls available in WinForms Use of Controls Control class Base class of all controls available in WinForms
Control Class – Properties-Method Event Click ControlAdd DoubleClick Validating Validated KeyPress Leave LostFocus MouseClick Move canFocus Controls Enable Name Parent TabIndex Visible Focus getNextControl Hide IsMNemonic Select Show
Common Controls
Label class : Property – Method- Event Properties Method Event Click Name Text TextAlign UseMnemonic Contains Hide Show Label fname = new Label(); fname.Text = “&First Name : “; fname.UseMnemonic = true ;
TextBox & MaskedTextBox
TextBox class : Property – Method- Event Properties Method Event KeyPress Leave TextChanged CharacterCasing MaxLength MultiLine Name PasswordChar ReadOnly Text AppendText Clear Focus Copy Paste
MaskedTextBox class : Property – Method- Event Properties Method Event MaskChanged MaskedInputRejected Mask MaskFull MaskCompleted Name PromptChar Text GetPositionFromCharIndex IsKeyLock SelectAll MaskedTextBox mks = new MaskedTextBox(); mks.Mask = “00000-9999”; mks.Text = “095204-7763”; if(!mks.MaskFull) { MessageBox.Show(“Enter proper code …”); }
Mask
Button class : Property – Method- Event Properties Method Event Click DoubleClick MouseDoubleClick DialogResult Enabled FlatStyle Image Name Text Focus PerformClick Button cmdOK = new Button(); cmdOK .Text = “OK” ; cmdOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
ListBox & ComboBox ListBox : select multivalue ( 1..N) ComboBox : select one value at a time
ListBox class : Property – Method- Event Properties Method Event DisplayMember Items SelectionMode SelectedIndex SelectedIndexChanged SelectedValueChanged ValueMemberChanged ClearSelected GetItemText GetSelected SetSelected
ComboBox class : Property – Method- Event Properties Method Event DropDown SelectedIndexChanged SelectedValueChanged ValueMemberChanged DropDownStyle Items MaxDropDownItem SelectedItem SelectedIndex Text ValueMember GetItemText SelectAll Select ( int start , int length)
Display a Hyperlink that link to a Web Page or another Window Form 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
Summary – WorkShop Activities What is WinForm ? Focus on Control TextBox , ListBox , ComBoBox ….
Grouping Controls Value Setting ControlForm class RadioButton CheckBox CheckListBox Grouping Controls GroupBox Panel Images Control PictureBox ImageList Summary
RadioButton Class – Properties-Method Event Appearance AutoCheck Checked Image PerformClick Select Show CheckedChanged Click
CheckBox class : Property – Method- Event Properties Method Event Checked CheckState ThreeState CheckedChanged CheckStateChange Click Select Show
CheckedListBox class : Property – Method- Event Properties Method Event CheckedIndices CheckedItems CheckOnClick Items SelectedValue SelectedItems SelectedItem ClearSelected GetItemChecked GetItemCheckState GetItemText SetItemChecked SetItemCheckState ItemCheck MouseClick SelectedIndexChanged SelectedValueChanged
Grouping Control Panel Contains other Control GroupBox As Panel but appear as Frame around Control
Panel class : Property – Method- Event Properties Method Event AutoSize AutoSizeMode BorderStyle StyleChanged VisibleChanged Select Show
GroupBox : Property – Method- Event Properties Method Event AutoSize Anchor FlatStyle StyleChanged Resize Hide Show
Graphic Controls PictureBox Display image on the Form ( .bmp ,.jpg ..) Can hold sigle image at a time ImageList Store collection of images
PictureBox : Property – Method- Event Properties Method Event Image ErrorImage InitialImage SizeMode Click Leave LoadCompleted Load LoadAsync
ImageList: Property – Method- Event Properties Method Event Images ColorDepth ImageSize Name RecreateHandle Draw
SplitContainer Divide the form into two resizable panels Properties BorderStyle FixedPanel IsSplitterFixed Panel1 Panel2 Orientation Method OnSplitterMoved OnSplitterMoving Divide the form into two resizable panels As Window Explorer Event SplitterMoved SplitterMoving Click
Summary – WorkShop Activities