Module 1 Window Forms – Basic, Grouping and Graphic controls 1
Objective Overview Window Form and basic Control Form class Types of Control Basic Controls Grouping an Graphic Controls 2
Application 3 User Interface - Easy to learn - Easy to use - Attractive Program
WinForms and.NET Framework Windows Forms : are a part of the.NET Framework that is used to build, deploy and run applications. Provide with a standard programing model in order to create application with least bugs. Are executed in the.NET CLR runtime. 4
Features Click one deployment Application setting New Windows Forms controls New Data Binding model Rich graphics 5 Create App with least operation Store global data to reuse anywhere Powerfull way to link control with data source ( BindingSource component ) GDI+ : drawing and painting image on forms ToolStrip, MenuStrip ….
Form Is the basic unit of an application Presents information to the user Receives information from the user. Is represented as a class in the System.Windows.Forms namespace. 6 Properties Text, BackColor, ForeColor, Font, WindowState, AcceptButton, Location, Modal, Name MethodsActivate, Close, Focus, Hide, Show, Enabled EventsLoad, Activated,Shown,Deactivate, FormClosing, FormClosed, Resize, Click, GotFocus
Use of Controls 7 Control class Base class of all controls available in WinForms
Control Class CanFocus Controls Enable Name Parent TabIndex Visible 8 Properties Focus GetNextControl Hide IsMNemonic Select Show Method Click ControlAdd DoubleClick Validating Validated KeyPress Leave LostFocus MouseClick Move Event Example this.[controlname].[propertyname]
Common Controls Label Textbox Button ListBox ComboBox LinkLabel 9
Label Name Text TextAlign UseMnemonic 10 Properties Contains Hide Show Method Click Event Label fName = new Label(); fname.Text = “&First Name : “; fName.UseMnemonic = true ; Label
TextBox CharacterCasing MaxLength MultiLine Name PasswordChar ReadOnly Text 11 AppendText Clear Focus Copy Paste KeyPress Leave TextChanged TextBox PropertiesMethodEvent
MaskedTextBox Mask MaskFull MaskCompleted Name PromptChar Text 12 GetPositionFrom CharIndex SelectAll MaskChanged MaskedInputRejected MaskedTextBox mks = new MaskedTextBox(); mks.Mask = “ ”; mks.Text = “ ”; if(!mks.MaskFull) { MessageBox.Show(“Enter proper code …”); } PropertiesMethodEvent
Mask Description 0Digit, required. [0-9] 9Digit or space, optional. # Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the property. Plus (+) and minus (-) are allowed. LLetter, required [a-zA-Z]. ?Letter, optional. [a-zA-Z]. &Character, required. If the property = true, behaves like the "L". C Character, optional. Any non-control character. If the property =true, this element behaves like the "?" element. A Alphanumeric, optional. If the property =true, the only characters it will accept are the ASCII letters a-z and A-Z. a Alphanumeric, optional. If the property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z. 13
Button DialogResult Enabled FlatStyle Image Name Text 14 Button cmdOK = new Button(); cmdOK.Text = “OK” ; cmdOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat; PropertiesMethodEvent Focus PerformClick Click DoubleClick MouseDoubleClick Button
ListBox Can select multivalues 15 DisplayMember Items SelectionMode SelectedIndex ClearSelected GetItemText GetSelected SetSelected SelectedIndexChanged SelectedValueChanged ValueMemberChanged PropertiesMethodEvent
ComboBox DropDownStyle Items MaxDropDownItem SelectedItem SelectedIndex Text ValueMember 16 GetItemText SelectAll Select (int start, int len) DropDown SelectedIndexChanged SelectedValueChanged ValueMemberChanged PropertiesMethodEvent
LinkLabel 17 Display a Hyperlink that link to a Web Page or another Window Form Properties: ActiveLinkColor, Links, LinkColor, LinkVisited, Text, VisitedLinkColor Method : Select Event : LinkClicked
Grouping Controls 18 Value Setting ControlForm class RadioButton CheckBox CheckListBox Grouping Controls GroupBox Panel Images Control PictureBox ImageList
RadioButton Appearance AutoCheck Checked Image 19 PerformClick Select Show CheckedChanged Click PropertiesMethodEvent
CheckBox Checked CheckState ThreeState 20 Select Show CheckedChanged CheckStateChange Click PropertiesMethodEvent
CheckedListBox CheckedIndices CheckedItems CheckOnClick Items SelectedValue SelectedItems SelectedItem 21 ClearSelected GetItemChecked GetItemCheckState GetItemText SetItemChecked SetItemCheckState ItemCheck MouseClick SelectedIndexChanged SelectedValueChanged PropertiesMethodEvent
Grouping Control Panel Contains other Control GroupBox As Panel but appear as Frame around Control 22
Panel AutoSize AutoSizeMode BorderStyle 23 Select Show StyleChanged VisibleChanged PropertiesMethodEvent
GroupBox AutoSize, Anchor, FlatStyle 24 Hide, Show StyleChanged, Resize Properties Method Event
Graphic Controls PictureBox Display image on the Form (.bmp,.jpg..) Can hold sigle image at a time ImageList Store collection of images 25
PictureBox Image ErrorImage InitialImage SizeMode 26 Load LoadAsync Click Leave LoadCompleted PropertiesMethodEvent
ImageList Images ColorDepth ImageSize Name 27 Draw RecreateHandle PropertiesMethodEvent
SplitContainer Divide the form into two resizable panels As Window Explorer 28 Properties BorderStyle FixedPanel IsSplitterFixed Panel1 Panel2 Orientation Method OnSplitterMoved OnSplitterMoving Event SplitterMoved SplitterMoving Click