SlideShare a Scribd company logo
1 of 60
Chapter 12 – Graphical User Interface Concepts: Part 1 Outline 12.1 Introduction 12.2   Windows Forms 12.3   Event-Handling Model 12.3.1  Basic Event Handling 12.4   Control Properties and Layout 12.5   Label s,  TextBoxes  and  Buttons 12.6   GroupBox es and  Panel s 12.7   CheckBox es and  RadioButton s 12.8   PictureBox es 12.9   Mouse-Event Handling 12.10   Keyboard-Event Handling
12.1  Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.1 Introduction Fig. 12.1 Sample Internet Explorer window with GUI components.
12.1 Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.1 Introduction Fig. 12.2 Some basic GUI components.
12.2   Windows Forms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.2 Windows Forms Fig. 12.3 Components and controls for Windows Forms.
12.2 Windows Forms Fig. 12.4 Common Form properties and events.
12.3   Event-Handling Model ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.3   Event-Handling Model Fig. 12.5 Event-handling model using delegates. Object A raises event E Delegate for event E Handler 1 for event E Handler 3 for event E Handler 2 for event E calls calls
12.3   Event-Handling Model Fig. 12.6 Events section of the Properties window.
SimpleEvenExample.vb 1  ' Fig. 12.7: SimpleEventExample.vb 2  ' Program demonstrating simple event handler. 3  4  Public   Class  FrmSimple 5  Inherits  System.Windows.Forms.Form 6  7   #Region  " Windows Form Designer generated code " 8  9  Public   Sub   New () 10  MyBase .New() 11  12  ' This call is required by the Windows Form Designer. 13  InitializeComponent() 14  15  16  ' Add any initialization after the  17  ' InitializeComponent() call 18  End   Sub  ' New 19  20  ' Form overrides dispose to clean up the component list. 21  Protected   Overloads   Overrides   Sub  Dispose( _  22  ByVal  disposing  As   Boolean ) 23  24  If  disposing  Then 25  26  If   Not  (components  Is   Nothing )  Then 27  components.Dispose() 28  End   If 29  30  End   If 31  32  MyBase .Dispose(disposing) 33  End   Sub  ' Dispose 34  35  Friend   WithEvents  lblOutput  As  System.Windows.Forms.Label Beginning of Visual Studio generated code
SimpleEvenExample.vb 36  37  ' Required by the Windows Form Designer 38  Private  components  As  System.ComponentModel.Container 39  40  ' NOTE: The following procedure is required by  41  ' the Windows Form Designer. 42  ' It can be modified using the Windows Form Designer.  43  ' Do not modify it using the code editor. 44  <System.Diagnostics.DebuggerStepThrough()>  _ 45  Private   Sub  InitializeComponent() 46  Me .lblOutput =  New  System.Windows.Forms.Label() 47  Me .SuspendLayout() 48  ' 49  'lblOutput 50  ' 51  Me .lblOutput.Location =  New  System.Drawing.Point( 32 ,  48 ) 52  Me .lblOutput.Name =  &quot;lblOutput&quot; 53  Me .lblOutput.Size =  New  System.Drawing.Size( 168 ,  40 ) 54  Me .lblOutput.TabIndex =  0 55  Me .lblOutput.Text =  &quot;Click Me!&quot; 56  ' 57  'FrmSimple 58  ' 59  Me .AutoScaleBaseSize =  New  System.Drawing.Size( 5 ,  13 ) 60  Me .ClientSize =  New  System.Drawing.Size( 272 ,  237 ) 61  Me .Controls.AddRange( _ 62  New  System.Windows.Forms.Control() { Me .lblOutput}) 63  64  Me .Name =  &quot;FrmSimple&quot; 65  Me .Text =  &quot;SimpleEventExample&quot; 66  Me .ResumeLayout( False ) 67  End   Sub 68  69   #End Region 70  End of Visual Studio generated code
SimpleEvenExample.vb 71  ' handler for click event on lblOutput 72   Private   Sub  lblOutput_Click( ByVal  sender  As  Object, _ 73   ByVal  e  As  System.EventArgs)  Handles  lblOutput.Click 74  75   MessageBox.Show( &quot;Label was pressed&quot; ) 76  End   Sub  ' lblOutput_Click 77  78  End   Class   ' FrmSimpleExample Name of the handler followed by an underscore and the event name Reference to the object that generated the event Event arguments object Event-handling code displays a message box
12.3   Event-Handling Model Fig. 12.8 List of Form events.
12.3   Event-Handling Model Fig. 12.9 Details of Click event.
12.4   Control Properties and Layout Fig. 12.10 Class Control properties and methods.
12.4   Control Properties and Layout ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.4   Control Properties and Layout ,[object Object],[object Object],[object Object],[object Object],[object Object]
12.4   Control Properties and Layout Fig. 12.11 Anchoring demonstration.
12.4   Control Properties and Layout Fig. 12.12 Manipulating the Anchor property of a control.
12.4   Control Properties and Layout Fig. 12.13 Docking demonstration.
12.4   Control Properties and Layout Fig. 12.14 Control layout properties.
12.5   Label s,  TextBoxes  and  Buttons ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.5   Label s,  TextBoxes  and  Buttons Fig. 12.15 Common Label properties.
12.5   Label s,  TextBoxes  and  Buttons Fig. 12.16 TextBox properties and events.
12.5   Label s,  TextBoxes  and  Buttons Fig. 12.17 Button properties and events.
LabelTextBoxButtonTest.vb 1  ' Fig. 12.18: LabelTextBoxButtonTest.vb 2  ' Using a textbox, label and button to display the hidden 3  ' text in a password box. 4  5  Public   Class  FrmButtonTest 6  Inherits  System.Windows.Forms.Form 7  8  ' Visual Studio .NET generated code 9  10  ' handles cmdShow_Click events 11  Private Sub  cmdShow_Click( ByVal  sender  As  System.Object, _ 12  ByVal  e  As  System.EventArgs)  Handles  cmdShow.Click 13  14   lblOutput.Text = txtInput.Text 15  End Sub  ' cmdShow_Click 16  17  End Class  ' FrmButtonTest The label’s text property is set equal to the value of the textbox’s text property, which was  entered by the user
12.6   GroupBox es and  Panel s ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.6   GroupBox es and  Panel s Fig. 12.19 GroupBox properties. Fig. 12.20 Panel properties.
12.6   GroupBox es and  Panel s Fig. 12.21 Creating a Panel with scrollbars.
GroupBoxPanelExample.vb 1  ' Fig. 12.22: GroupBoxPanelExample.vb  2  ' Using GroupBoxes and Panels to hold buttons. 3  4  Public Class  FrmGroupBox 5  Inherits  System.Windows.Forms.Form 6  7  ' Visual Studio.NET generated code 8  9  ' event handlers to change lblMessage 10  Private Sub  cmdHi_Click( ByVal  sender  As  System.Object, _ 11  ByVal  e  As  System.EventArgs)  Handles  cmdHi.Click 12  13   lblMessage.Text =  &quot;Hi pressed&quot;   14  End Sub  ' cmdHi_Click 15  16  ' bye button handler 17  Private Sub  cmdBye_Click( ByVal  sender  As  System.Object, _ 18  ByVal  e  As  System.EventArgs)  Handles  cmdBye.Click 19  20  lblMessage.Text =  &quot;Bye pressed&quot;   21  End Sub  ' cmdBye_Click 22  23  ' far left button handler 24  Private Sub  cmdLeft_Click( ByVal  sender  As  System.Object, _ 25  ByVal  e  As  System.EventArgs)  Handles  cmdLeft.Click 26  27  lblMessage.Text =  &quot;Far left pressed&quot; 28  End Sub  ' cmdLeft_Click 29  Event handling code  displays the appropriate text property for lbl.Message
GroupBoxPanelExample.vb 30  ' far right button handler 31  Private Sub  cmdRight_Click( ByVal  sender  As  System.Object, _ 32  ByVal  e  As  System.EventArgs)  Handles  cmdRight.Click 33  34  lblMessage.Text =  &quot;Far right pressed&quot; 35  End Sub  ' cmdRight_Click 36  37  End Class  ' FrmGroupBox
12.7   CheckBox es and  RadioButton s ,[object Object],[object Object],[object Object],[object Object],[object Object]
12.7   CheckBox es and  RadioButton s Fig. 12.23 CheckBox properties and events.
CheckBoxTest.vb 1  ' Fig. 12.24: CheckBoxTest.vb 2  ' Using CheckBoxes to toggle italic and bold styles. 3  4  Public   Class  FrmCheckBox 5  Inherits  System.Windows.Forms.Form 6  7  ' Visual Studio .NET IDE generated code 8  9  ' use Xor to toggle italic, keep other styles same 10  Private   Sub  chkItalic_CheckedChanged _ 11  ( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs) _ 12  Handles  chkItalic.CheckedChanged 13  14  lblOutput.Font =  New  Font(lblOutput.Font.Name, _ 15  lblOutput.Font.Size, lblOutput.Font.Style _ 16  Xor  FontStyle.Italic) 17  End   Sub   ' chkItalic_CheckedChanged 18  19  ' use Xor to toggle bold, keep other styles same 20  Private   Sub  chkBold_CheckedChanged _ 21  ( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs) _ 22  Handles  chkBold.CheckedChanged 23  24  lblOutput.Font =  New  Font(lblOutput.Font.Name, _ 25  lblOutput.Font.Size, lblOutput.Font.Style _ 26  Xor  FontStyle.Bold) 27  End   Sub   ' chkBold_CheckedChanged 28  29  End Class   ' FrmCheckBox
CheckBoxTest.vb
12.7   CheckBox es and  RadioButton s Fig. 12.25 RadioButton properties and events.
RadioButtonTest.vb 1  ' Fig. 12.26: RadioButtonTest.vb 2  ' Using RadioButtons to set message window options. 3  4  Public   Class  FrmRadioButton 5  Inherits  System.Windows.Forms.Form 6  7  Private  iconType  As  MessageBoxIcon 8  Private  buttonType  As  MessageBoxButtons 9  10  ' Visual Studio .NET generated code 11  12  ' display message box and obtain dialogue button clicked 13  Private   Sub  cmdDisplay_Click( ByVal  sender _ 14  As  System.Object,  ByVal  e  As  System.EventArgs) _ 15  Handles  cmdDisplay.Click 16  17  Dim  dialog  As  DialogResult = MessageBox.Show( _ 18  &quot;This is Your Custom MessageBox&quot; ,  &quot;VB&quot; , buttonType, _ 19  iconType) 20  21  ' check for dialog result and display on label 22  Select   Case  dialog 23  24  Case  DialogResult. OK 25  lblDisplay.Text =  &quot;OK was pressed&quot; 26  27  Case  DialogResult. Cancel 28  lblDisplay.Text =  &quot;Cancel was pressed&quot; 29  30  Case  DialogResult. Abort 31  lblDisplay.Text =  &quot;Abort was pressed&quot; 32  33  Case  DialogResult. Retry 34  lblDisplay.Text =  &quot;Retry was pressed&quot; 35
RadioButtonTest.vb 36  Case  DialogResult. Ignore 37  lblDisplay.Text =  &quot;Ignore was pressed&quot; 38  39  Case  DialogResult. Yes 40  lblDisplay.Text =  &quot;Yes was pressed&quot; 41  42  Case  DialogResult. No 43  lblDisplay.Text =  &quot;No was pressed&quot; 44  End   Select 45  46  End   Sub   ' cmdDisplay_Click 47  48  ' set button type to OK 49  Private   Sub  radOk_CheckedChanged( ByVal  sender _ 50  As  System.Object,  ByVal  e  As  System.EventArgs) _ 51  Handles  radOk.CheckedChanged 52  53  buttonType = MessageBoxButtons. OK 54  End   Sub  ' radOk_CheckedChanged 55  56  ' set button type to OkCancel 57  Private   Sub  radOkCancel_CheckedChanged( ByVal  sender _ 58  As  System.Object,  ByVal  e  As  System.EventArgs) _ 59  Handles  radOkCancel.CheckedChanged 60  61  buttonType = MessageBoxButtons. OKCancel 62  End   Sub  ' radOkCancel_CheckedChanged 63  64  ' set button type to AbortRetryIgnore 65  Private   Sub  radAbortRetryIgnore_CheckedChanged( ByVal  sender _ 66  As  System.Object,  ByVal  e  As  System.EventArgs) _ 67  Handles  radAbortRetryIgnore.CheckedChanged 68  69  buttonType = MessageBoxButtons. AbortRetryIgnore 70  End Sub  ' radAbortRetryIgnore_CheckedChanged
RadioButtonTest.vb 71  72  ' set button type to YesNoCancel 73  Private   Sub  radYesNoCancel_CheckedChanged( ByVal  sender _ 74  As  System.Object,  ByVal  e  As  System.EventArgs) _ 75  Handles  radYesNoCancel.CheckedChanged 76  77  buttonType = MessageBoxButtons. YesNoCancel 78  End   Sub  ' radYesNoCancel_CheckedChanged 79  80  ' set button type to YesNo 81  Private   Sub  radYesNo_CheckedChanged( ByVal  sender _ 82  As  System.Object,  ByVal  e  As  System.EventArgs) _ 83  Handles  radYesNo.CheckedChanged 84  85  buttonType = MessageBoxButtons. YesNo 86  End   Sub  ' radYesNo_CheckedChanged 87  88  ' set button type to RetryCancel  89  Private   Sub  radRetryCancel_CheckedChanged( ByVal  sender _ 90  As  System.Object,  ByVal  e  As  System.EventArgs) _ 91  Handles  radRetryCancel.CheckedChanged 92  93  buttonType = MessageBoxButtons. RetryCancel 94  End Sub  ' radRetryCancel_CheckedChanged 95  96  ' set icon type to Asterisk when Asterisk checked 97  Private   Sub  radAsterisk_CheckedChanged( ByVal  sender _ 98  As  System.Object,  ByVal  e  As  System.EventArgs) _ 99  Handles  radAsterisk.CheckedChanged 100  101  iconType = MessageBoxIcon. Asterisk 102  End Sub  ' radAsterisk_CheckedChanged 103
RadioButtonTest.vb 104  ' set icon type to Error when Error checked 105  Private   Sub  radError_CheckedChanged( ByVal  sender _ 106  As  System.Object,  ByVal  e  As  System.EventArgs) _ 107  Handles  radError.CheckedChanged 108  109  iconType = MessageBoxIcon. Error 110  End Sub  ' radError_CheckedChanged 111  112  ' set icon type to Exclamation when Exclamation checked 113  Private   Sub  radExclamation_CheckedChanged( ByVal  sender _ 114  As  System.Object,  ByVal  e  As  System.EventArgs) _ 115  Handles  radExclamation.CheckedChanged 116  117  iconType = MessageBoxIcon. Exclamation 118  End Sub  ' radExclamation_CheckedChanged 119  120  ' set icon type to Hand when Hand checked 121  Private   Sub  radHand_CheckedChanged( ByVal  sender _ 122  As  System.Object,  ByVal  e  As  System.EventArgs) _ 123  Handles  radHand.CheckedChanged 124  125  iconType = MessageBoxIcon. Hand 126  End Sub  ' radHand_CheckedChanged 127  128  ' set icon type to Information when Information checked 129  Private   Sub  radInformation_CheckedChanged( ByVal  sender _ 130  As  System.Object,  ByVal  e  As  System.EventArgs) _ 131  Handles  radInformation.CheckedChanged 132  133  iconType = MessageBoxIcon. Information 134  End Sub  ' radInformation_CheckedChanged 135
RadioButtonTest.vb 136  ' set icon type to Question when Question checked 137  Private   Sub  radQuestion_CheckedChanged( ByVal  sender _ 138  As  System.Object,  ByVal  e  As  System.EventArgs) _ 139  Handles  radQuestion.CheckedChanged 140  141  iconType = MessageBoxIcon. Question 142  End Sub  ' radQuestion_CheckedChanged 143  144  ' set icon type to Stop when Stop checked 145  Private   Sub  radStop_CheckedChanged( ByVal  sender _ 146  As  System.Object,  ByVal  e  As  System.EventArgs) _ 147  Handles  radStop.CheckedChanged 148  149  iconType = MessageBoxIcon. Stop 150  End Sub  ' radStop_CheckedChanged 151  152  ' set icon type to Warning when Warning checked 153  Private   Sub  radWarning_CheckedChanged( ByVal  sender _ 154  As  System.Object,  ByVal  e  As  System.EventArgs) _ 155  Handles  radWarning.CheckedChanged 156  157  iconType = MessageBoxIcon. Warning 158  End Sub  ' radWarning_CheckedChanged 159  160  End   Class   ' FrmRadioButtons
RadioButtonTest.vb
RadioButtonTest.vb
RadioButtonTest.vb
RadioButtonTest.vb
12.8   PictureBox es ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.8   PictureBox es Fig. 12.30 PictureBox properties and events.
PictureBoxTest.vb 1  ' Fig. 12.31: PictureBoxTest.vb 2  ' Using a PictureBox to display images. 3  4  Imports  System.IO 5  6  Public Class  FrmPictureBox 7  Inherits  System.Windows.Forms.Form 8  9  Private  imageNumber  As Integer  =  -1 10  11  ' Visual Studio.NET generated code 12  13  ' replace image in picImage 14  Private Sub  picImage_Click( ByVal  sender  As  System.Object, _ 15  ByVal  e  As  System.EventArgs)  Handles  picImage.Click 16  17  ' imageNumber from 0 to 2 18  imageNumber = (imageNumber +  1 )  Mod   3   19  20  ' create Image object from file, display in PictureBox 21   picImage.Image = Image.FromFile _ 22  (Directory.GetCurrentDirectory &  &quot;magesmage&quot;  & _ 23  imageNumber &  &quot;.bmp&quot; ) 24  End Sub  ' picImage_Click 25  26  End Class  ' FrmPictureBox An image object is created from file and set as the  PictureBox’s image property
 
12.9  Mouse-Event Handling ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.9  Mouse-Event Handling Fig. 12.32 Mouse events, delegates and event arguments.
Painter.vb 1  ' Fig. 12.33: Painter.vb 2  ' Using the mouse to draw on a form. 3  4  Public   Class  FrmPainter 5  Inherits  System.Windows.Forms.Form 6  7  Dim  shouldPaint  As   Boolean  =  False 8  9  ' Visual Studio .NET IDE generated code 10  11  ' draw circle if shouldPaint is True 12  Private   Sub  FrmPainter_MouseMove( _ 13  ByVal  sender  As  System.Object, _ 14  ByVal  e  As  System.Windows.Forms.MouseEventArgs) _ 15  Handles  MyBase.MouseMove 16  17  ' paint circle if mouse pressed 18   If  shouldPaint  Then 19  Dim  graphic  As  Graphics = CreateGraphics() 20  21  graphic.FillEllipse _ 22  ( New  SolidBrush(Color. BlueViolet ), e.X, e.Y,  4 ,  4 ) 23  End   If 24  25  End   Sub   ' FrmPainter_MouseMove 26  27  ' set shouldPaint to True 28  Private   Sub  FrmPainter_MouseDown( ByVal  sender  As  Object, _ 29  ByVal  e  As  System.Windows.Forms.MouseEventArgs) _ 30  Handles  MyBase.MouseDown 31  32   shouldPaint =  True 33  End   Sub   ' FrmPainter_MousDown 34  Event handling for Mouse event  MouseDown sets variable  shouldPaint to True Event handling code begins for event MouseMove
Painter.vb 35  ' set shouldPaint to False  36  Private   Sub  FrmPainter_MouseUp( ByVal  sender  As  Object, _ 37  ByVal  e  As  System.Windows.Forms.MouseEventArgs) _ 38  Handles  MyBase.MouseUp 39  40   shouldPaint =  False 41  End   Sub   ' FrmPainter_MouseUp 42  43  End   Class   ' FrmPainter Event handling for Mouse event  MouseUp sets variable  shouldPaint to False
12.10  Keyboard-Event Handling ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
12.10  Keyboard-Event Handling Fig. 12.34 Keyboard events, delegates and event arguments.
KeyDemo.vb 1  ' Fig. 12.35: KeyDemo.vb 2  ' Displaying information about a user-pressed key. 3  4  Public Class  FrmKeyDemo 5  Inherits  System.Windows.Forms.Form 6  7  ' Visual Studio.NET generated code 8  9  ' event handler for key press 10  Private Sub  FrmKeyDemo_KeyPress( ByVal  sender  As  System.Object, _ 11  ByVal  e  As  System.windows.Forms.KeyPressEventArgs) _ 12  Handles MyBase .KeyPress 13  14   lblCharacter.Text =  &quot;Key pressed: &quot;  & e.KeyChar 15  End Sub 16  17  ' display modifier keys, key code, key data and key value 18  Private Sub  FrmKeyDemo_KeyDown( ByVal  sender  As  System.Object, _ 19  ByVal  e  As  System.Windows.Forms.KeyEventArgs) _ 20  Handles MyBase .KeyDown 21  22  lblInformation.Text =  &quot;&quot; 23  24  ' if key is Alt 25   If  e.Alt  Then 26  lblInformation.Text &=  &quot;Alt: Yes&quot;  &  vbCrLf 27  Else 28  lblInformation.Text &=  &quot;Alt: No&quot;  &  vbCrLf 29  End If 30  KeyDown event handler displays information from its KeyEventArgs object KeyPress event handler accesses the KeyChar property of the KeyPressEventArgs object and displays the Key
KeyDemo.vb 31  ' if key is Shift 32  If  e.Shift  Then 33  lblInformation.Text &=  &quot;Shift: Yes&quot;  &  vbCrLf 34  Else 35  lblInformation.Text &=  &quot;Shift: No&quot;  &  vbCrLf 36  End If 37  38  ' if key is Ctrl 39  If  e.Control  Then 40  lblInformation.Text &=  &quot;Ctrl: Yes&quot;  &  vbCrLf  & _ 41   &quot;KeyCode: &quot;  & e.KeyCode.ToString &  vbCrLf  &  _ 42  &quot;KeyData: &quot;  & e.KeyData.ToString &  vbCrLf  & _ 43  &quot;KeyValue: &quot;  & e.KeyValue 44  Else 45  lblInformation.Text &=  &quot;Ctrl: No&quot;  &  vbCrLf  & _ 46  &quot;KeyCode: &quot;  & e.KeyCode.ToString &  vbCrLf  &  _ 47  &quot;KeyData: &quot;  & e.KeyData.ToString &  vbCrLf  & _ 48  &quot;KeyValue: &quot;  & e.KeyValue 49  End If 50  51  End Sub  ' FrmKeyDemo_KeyDown 52  53  ' clear labels when key is released 54  Private Sub  FrmKeyDemo_KeyUp( ByVal  sender  As  System.Object, _ 55  ByVal  e  As  System.windows.Forms.KeyEventArgs) _ 56  Handles   MyBase .KeyUp 57  58   lblInformation.Text =  &quot;&quot; 59  lblCharacter.Text =  &quot;&quot; 60  End Sub  ' FrmKeyDemo_KeyUp 61  62  End Class  ' FrmKeyDemo The KeyCode property returns a Keys enumeration, which must be converted to a String via method ToString Both labels are cleared when a key is released
KeyDemo.vb

More Related Content

What's hot

The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184Mahmoud Samir Fayed
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Bhushan Mulmule
 
iOS Contact List Application Tutorial
iOS Contact List Application TutorialiOS Contact List Application Tutorial
iOS Contact List Application TutorialIshara Amarasekera
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training Moutasm Tamimi
 
Programming Without Coding Technology (PWCT) - ShellExplorer Sample
Programming Without Coding Technology (PWCT) - ShellExplorer SampleProgramming Without Coding Technology (PWCT) - ShellExplorer Sample
Programming Without Coding Technology (PWCT) - ShellExplorer SampleMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...
Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...
Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Internet Explorer ActiveX Control
Programming Without Coding Technology (PWCT) - Internet Explorer ActiveX ControlProgramming Without Coding Technology (PWCT) - Internet Explorer ActiveX Control
Programming Without Coding Technology (PWCT) - Internet Explorer ActiveX ControlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Mahmoud Samir Fayed
 
Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vbAmandeep Kaur
 
Microsoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVP
Microsoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVPMicrosoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVP
Microsoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVPGilbok Lee
 
20150812 4시간만에 따라해보는 windows 10 앱 개발
20150812  4시간만에 따라해보는 windows 10 앱 개발20150812  4시간만에 따라해보는 windows 10 앱 개발
20150812 4시간만에 따라해보는 windows 10 앱 개발영욱 김
 
Programming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash MovieProgramming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash MovieMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...
Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...
Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...
Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...
Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Add toolbar to the window
Programming Without Coding Technology (PWCT) - Add toolbar to the windowProgramming Without Coding Technology (PWCT) - Add toolbar to the window
Programming Without Coding Technology (PWCT) - Add toolbar to the windowMahmoud Samir Fayed
 

What's hot (20)

Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
4.C#
4.C#4.C#
4.C#
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
iOS Contact List Application Tutorial
iOS Contact List Application TutorialiOS Contact List Application Tutorial
iOS Contact List Application Tutorial
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
Programming Without Coding Technology (PWCT) - ShellExplorer Sample
Programming Without Coding Technology (PWCT) - ShellExplorer SampleProgramming Without Coding Technology (PWCT) - ShellExplorer Sample
Programming Without Coding Technology (PWCT) - ShellExplorer Sample
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...
Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...
Programming Without Coding Technology (PWCT) - Show PDF using InternetExplore...
 
Programming Without Coding Technology (PWCT) - Internet Explorer ActiveX Control
Programming Without Coding Technology (PWCT) - Internet Explorer ActiveX ControlProgramming Without Coding Technology (PWCT) - Internet Explorer ActiveX Control
Programming Without Coding Technology (PWCT) - Internet Explorer ActiveX Control
 
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10
 
Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vb
 
Microsoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVP
Microsoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVPMicrosoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVP
Microsoft MVP ComCamp 2014 발표자료 / 윈도우 8.1 앱개발 새로운 API들 / 이길복, 주신영 MVP
 
20150812 4시간만에 따라해보는 windows 10 앱 개발
20150812  4시간만에 따라해보는 windows 10 앱 개발20150812  4시간만에 따라해보는 windows 10 앱 개발
20150812 4시간만에 따라해보는 windows 10 앱 개발
 
Programming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash MovieProgramming Without Coding Technology (PWCT) - Play Flash Movie
Programming Without Coding Technology (PWCT) - Play Flash Movie
 
Vs c# lecture1
Vs c# lecture1Vs c# lecture1
Vs c# lecture1
 
Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...
Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...
Programming Without Coding Technology (PWCT) - Encrypt/Decrypt Files using Po...
 
Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...
Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...
Programming Without Coding Technology (PWCT) - Compress Files using PolarZipL...
 
Programming Without Coding Technology (PWCT) - Add toolbar to the window
Programming Without Coding Technology (PWCT) - Add toolbar to the windowProgramming Without Coding Technology (PWCT) - Add toolbar to the window
Programming Without Coding Technology (PWCT) - Add toolbar to the window
 

Viewers also liked

Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To DotnetSAMIR BHOGAYTA
 
SE - Software Requirements
SE - Software RequirementsSE - Software Requirements
SE - Software RequirementsJomel Penalba
 
Mental models
Mental modelsMental models
Mental modelsaukee
 
Ch5 - Project Management
Ch5 - Project ManagementCh5 - Project Management
Ch5 - Project ManagementJomel Penalba
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2Jomel Penalba
 
Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1Jomel Penalba
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application veera
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual BasicTushar Jain
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
 

Viewers also liked (20)

Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
 
Crm
CrmCrm
Crm
 
Business hardware
Business hardwareBusiness hardware
Business hardware
 
SE - Software Requirements
SE - Software RequirementsSE - Software Requirements
SE - Software Requirements
 
Mental models
Mental modelsMental models
Mental models
 
Ch5 - Project Management
Ch5 - Project ManagementCh5 - Project Management
Ch5 - Project Management
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
 
06 procedures
06 procedures06 procedures
06 procedures
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
SE - System Models
SE - System ModelsSE - System Models
SE - System Models
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
 
Gu iintro(java)
Gu iintro(java)Gu iintro(java)
Gu iintro(java)
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Chapter03 Ppt
Chapter03 PptChapter03 Ppt
Chapter03 Ppt
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 

Similar to 12 gui concepts 1

06 win forms
06 win forms06 win forms
06 win formsmrjw
 
03 intro to vb programming
03 intro to vb programming03 intro to vb programming
03 intro to vb programmingJomel Penalba
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic ProgrammingOsama Yaseen
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13HUST
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshopdhi her
 
Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesDavid Voyles
 
Chapter 08
Chapter 08Chapter 08
Chapter 08llmeade
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Jeanie Arnoco
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.pptLalRatan
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docxamrit47
 

Similar to 12 gui concepts 1 (20)

06 win forms
06 win forms06 win forms
06 win forms
 
03 intro to vb programming
03 intro to vb programming03 intro to vb programming
03 intro to vb programming
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Dojo1.0_Tutorials
Dojo1.0_TutorialsDojo1.0_Tutorials
Dojo1.0_Tutorials
 
Dojo1.0_Tutorials
Dojo1.0_TutorialsDojo1.0_Tutorials
Dojo1.0_Tutorials
 
Ppt lesson 03
Ppt lesson 03Ppt lesson 03
Ppt lesson 03
 
Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile services
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
SPF WinForm Programs
SPF WinForm ProgramsSPF WinForm Programs
SPF WinForm Programs
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
L11cs2110sp13
L11cs2110sp13L11cs2110sp13
L11cs2110sp13
 
Gui builder
Gui builderGui builder
Gui builder
 
Android
AndroidAndroid
Android
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.ppt
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 

More from Jomel Penalba

Requirements Engineering Process
Requirements Engineering ProcessRequirements Engineering Process
Requirements Engineering ProcessJomel Penalba
 
Copy of business hardware
Copy of business hardwareCopy of business hardware
Copy of business hardwareJomel Penalba
 
Business functions and supply chains
Business functions and supply chainsBusiness functions and supply chains
Business functions and supply chainsJomel Penalba
 
Laboratory activity 3 b3
Laboratory activity 3 b3Laboratory activity 3 b3
Laboratory activity 3 b3Jomel Penalba
 
Laboratory activity 3 b2
Laboratory activity 3 b2Laboratory activity 3 b2
Laboratory activity 3 b2Jomel Penalba
 
Laboratory activity 3 b1
Laboratory activity 3 b1Laboratory activity 3 b1
Laboratory activity 3 b1Jomel Penalba
 
Software process models
Software process modelsSoftware process models
Software process modelsJomel Penalba
 
02 intro to vb-net ide
02 intro to vb-net ide02 intro to vb-net ide
02 intro to vb-net ideJomel Penalba
 
Soft Eng - Software Process
Soft  Eng - Software ProcessSoft  Eng - Software Process
Soft Eng - Software ProcessJomel Penalba
 
Soft Eng - Introduction
Soft Eng - IntroductionSoft Eng - Introduction
Soft Eng - IntroductionJomel Penalba
 
Planning Your Multimedia Web Site
Planning Your Multimedia Web SitePlanning Your Multimedia Web Site
Planning Your Multimedia Web SiteJomel Penalba
 
Introduction To Multimedia
Introduction To MultimediaIntroduction To Multimedia
Introduction To MultimediaJomel Penalba
 

More from Jomel Penalba (14)

Requirements Engineering Process
Requirements Engineering ProcessRequirements Engineering Process
Requirements Engineering Process
 
Copy of business hardware
Copy of business hardwareCopy of business hardware
Copy of business hardware
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Business functions and supply chains
Business functions and supply chainsBusiness functions and supply chains
Business functions and supply chains
 
Laboratory activity 3 b3
Laboratory activity 3 b3Laboratory activity 3 b3
Laboratory activity 3 b3
 
Laboratory activity 3 b2
Laboratory activity 3 b2Laboratory activity 3 b2
Laboratory activity 3 b2
 
Laboratory activity 3 b1
Laboratory activity 3 b1Laboratory activity 3 b1
Laboratory activity 3 b1
 
Software process models
Software process modelsSoftware process models
Software process models
 
02 intro to vb-net ide
02 intro to vb-net ide02 intro to vb-net ide
02 intro to vb-net ide
 
01 intro to vb-net
01 intro to vb-net01 intro to vb-net
01 intro to vb-net
 
Soft Eng - Software Process
Soft  Eng - Software ProcessSoft  Eng - Software Process
Soft Eng - Software Process
 
Soft Eng - Introduction
Soft Eng - IntroductionSoft Eng - Introduction
Soft Eng - Introduction
 
Planning Your Multimedia Web Site
Planning Your Multimedia Web SitePlanning Your Multimedia Web Site
Planning Your Multimedia Web Site
 
Introduction To Multimedia
Introduction To MultimediaIntroduction To Multimedia
Introduction To Multimedia
 

12 gui concepts 1

  • 1. Chapter 12 – Graphical User Interface Concepts: Part 1 Outline 12.1 Introduction 12.2   Windows Forms 12.3   Event-Handling Model 12.3.1  Basic Event Handling 12.4   Control Properties and Layout 12.5   Label s, TextBoxes and Buttons 12.6   GroupBox es and Panel s 12.7   CheckBox es and RadioButton s 12.8   PictureBox es 12.9   Mouse-Event Handling 12.10   Keyboard-Event Handling
  • 2.
  • 3. 12.1 Introduction Fig. 12.1 Sample Internet Explorer window with GUI components.
  • 4.
  • 5. 12.1 Introduction Fig. 12.2 Some basic GUI components.
  • 6.
  • 7. 12.2 Windows Forms Fig. 12.3 Components and controls for Windows Forms.
  • 8. 12.2 Windows Forms Fig. 12.4 Common Form properties and events.
  • 9.
  • 10. 12.3   Event-Handling Model Fig. 12.5 Event-handling model using delegates. Object A raises event E Delegate for event E Handler 1 for event E Handler 3 for event E Handler 2 for event E calls calls
  • 11. 12.3   Event-Handling Model Fig. 12.6 Events section of the Properties window.
  • 12. SimpleEvenExample.vb 1 ' Fig. 12.7: SimpleEventExample.vb 2 ' Program demonstrating simple event handler. 3 4 Public Class FrmSimple 5 Inherits System.Windows.Forms.Form 6 7 #Region &quot; Windows Form Designer generated code &quot; 8 9 Public Sub New () 10 MyBase .New() 11 12 ' This call is required by the Windows Form Designer. 13 InitializeComponent() 14 15 16 ' Add any initialization after the 17 ' InitializeComponent() call 18 End Sub ' New 19 20 ' Form overrides dispose to clean up the component list. 21 Protected Overloads Overrides Sub Dispose( _ 22 ByVal disposing As Boolean ) 23 24 If disposing Then 25 26 If Not (components Is Nothing ) Then 27 components.Dispose() 28 End If 29 30 End If 31 32 MyBase .Dispose(disposing) 33 End Sub ' Dispose 34 35 Friend WithEvents lblOutput As System.Windows.Forms.Label Beginning of Visual Studio generated code
  • 13. SimpleEvenExample.vb 36 37 ' Required by the Windows Form Designer 38 Private components As System.ComponentModel.Container 39 40 ' NOTE: The following procedure is required by 41 ' the Windows Form Designer. 42 ' It can be modified using the Windows Form Designer. 43 ' Do not modify it using the code editor. 44 <System.Diagnostics.DebuggerStepThrough()> _ 45 Private Sub InitializeComponent() 46 Me .lblOutput = New System.Windows.Forms.Label() 47 Me .SuspendLayout() 48 ' 49 'lblOutput 50 ' 51 Me .lblOutput.Location = New System.Drawing.Point( 32 , 48 ) 52 Me .lblOutput.Name = &quot;lblOutput&quot; 53 Me .lblOutput.Size = New System.Drawing.Size( 168 , 40 ) 54 Me .lblOutput.TabIndex = 0 55 Me .lblOutput.Text = &quot;Click Me!&quot; 56 ' 57 'FrmSimple 58 ' 59 Me .AutoScaleBaseSize = New System.Drawing.Size( 5 , 13 ) 60 Me .ClientSize = New System.Drawing.Size( 272 , 237 ) 61 Me .Controls.AddRange( _ 62 New System.Windows.Forms.Control() { Me .lblOutput}) 63 64 Me .Name = &quot;FrmSimple&quot; 65 Me .Text = &quot;SimpleEventExample&quot; 66 Me .ResumeLayout( False ) 67 End Sub 68 69 #End Region 70 End of Visual Studio generated code
  • 14. SimpleEvenExample.vb 71 ' handler for click event on lblOutput 72 Private Sub lblOutput_Click( ByVal sender As Object, _ 73 ByVal e As System.EventArgs) Handles lblOutput.Click 74 75 MessageBox.Show( &quot;Label was pressed&quot; ) 76 End Sub ' lblOutput_Click 77 78 End Class ' FrmSimpleExample Name of the handler followed by an underscore and the event name Reference to the object that generated the event Event arguments object Event-handling code displays a message box
  • 15. 12.3   Event-Handling Model Fig. 12.8 List of Form events.
  • 16. 12.3   Event-Handling Model Fig. 12.9 Details of Click event.
  • 17. 12.4   Control Properties and Layout Fig. 12.10 Class Control properties and methods.
  • 18.
  • 19.
  • 20. 12.4   Control Properties and Layout Fig. 12.11 Anchoring demonstration.
  • 21. 12.4   Control Properties and Layout Fig. 12.12 Manipulating the Anchor property of a control.
  • 22. 12.4   Control Properties and Layout Fig. 12.13 Docking demonstration.
  • 23. 12.4   Control Properties and Layout Fig. 12.14 Control layout properties.
  • 24.
  • 25. 12.5   Label s, TextBoxes and Buttons Fig. 12.15 Common Label properties.
  • 26. 12.5   Label s, TextBoxes and Buttons Fig. 12.16 TextBox properties and events.
  • 27. 12.5   Label s, TextBoxes and Buttons Fig. 12.17 Button properties and events.
  • 28. LabelTextBoxButtonTest.vb 1 ' Fig. 12.18: LabelTextBoxButtonTest.vb 2 ' Using a textbox, label and button to display the hidden 3 ' text in a password box. 4 5 Public Class FrmButtonTest 6 Inherits System.Windows.Forms.Form 7 8 ' Visual Studio .NET generated code 9 10 ' handles cmdShow_Click events 11 Private Sub cmdShow_Click( ByVal sender As System.Object, _ 12 ByVal e As System.EventArgs) Handles cmdShow.Click 13 14 lblOutput.Text = txtInput.Text 15 End Sub ' cmdShow_Click 16 17 End Class ' FrmButtonTest The label’s text property is set equal to the value of the textbox’s text property, which was entered by the user
  • 29.
  • 30. 12.6   GroupBox es and Panel s Fig. 12.19 GroupBox properties. Fig. 12.20 Panel properties.
  • 31. 12.6   GroupBox es and Panel s Fig. 12.21 Creating a Panel with scrollbars.
  • 32. GroupBoxPanelExample.vb 1 ' Fig. 12.22: GroupBoxPanelExample.vb 2 ' Using GroupBoxes and Panels to hold buttons. 3 4 Public Class FrmGroupBox 5 Inherits System.Windows.Forms.Form 6 7 ' Visual Studio.NET generated code 8 9 ' event handlers to change lblMessage 10 Private Sub cmdHi_Click( ByVal sender As System.Object, _ 11 ByVal e As System.EventArgs) Handles cmdHi.Click 12 13 lblMessage.Text = &quot;Hi pressed&quot; 14 End Sub ' cmdHi_Click 15 16 ' bye button handler 17 Private Sub cmdBye_Click( ByVal sender As System.Object, _ 18 ByVal e As System.EventArgs) Handles cmdBye.Click 19 20 lblMessage.Text = &quot;Bye pressed&quot; 21 End Sub ' cmdBye_Click 22 23 ' far left button handler 24 Private Sub cmdLeft_Click( ByVal sender As System.Object, _ 25 ByVal e As System.EventArgs) Handles cmdLeft.Click 26 27 lblMessage.Text = &quot;Far left pressed&quot; 28 End Sub ' cmdLeft_Click 29 Event handling code displays the appropriate text property for lbl.Message
  • 33. GroupBoxPanelExample.vb 30 ' far right button handler 31 Private Sub cmdRight_Click( ByVal sender As System.Object, _ 32 ByVal e As System.EventArgs) Handles cmdRight.Click 33 34 lblMessage.Text = &quot;Far right pressed&quot; 35 End Sub ' cmdRight_Click 36 37 End Class ' FrmGroupBox
  • 34.
  • 35. 12.7   CheckBox es and RadioButton s Fig. 12.23 CheckBox properties and events.
  • 36. CheckBoxTest.vb 1 ' Fig. 12.24: CheckBoxTest.vb 2 ' Using CheckBoxes to toggle italic and bold styles. 3 4 Public Class FrmCheckBox 5 Inherits System.Windows.Forms.Form 6 7 ' Visual Studio .NET IDE generated code 8 9 ' use Xor to toggle italic, keep other styles same 10 Private Sub chkItalic_CheckedChanged _ 11 ( ByVal sender As System.Object, ByVal e As System.EventArgs) _ 12 Handles chkItalic.CheckedChanged 13 14 lblOutput.Font = New Font(lblOutput.Font.Name, _ 15 lblOutput.Font.Size, lblOutput.Font.Style _ 16 Xor FontStyle.Italic) 17 End Sub ' chkItalic_CheckedChanged 18 19 ' use Xor to toggle bold, keep other styles same 20 Private Sub chkBold_CheckedChanged _ 21 ( ByVal sender As System.Object, ByVal e As System.EventArgs) _ 22 Handles chkBold.CheckedChanged 23 24 lblOutput.Font = New Font(lblOutput.Font.Name, _ 25 lblOutput.Font.Size, lblOutput.Font.Style _ 26 Xor FontStyle.Bold) 27 End Sub ' chkBold_CheckedChanged 28 29 End Class ' FrmCheckBox
  • 38. 12.7   CheckBox es and RadioButton s Fig. 12.25 RadioButton properties and events.
  • 39. RadioButtonTest.vb 1 ' Fig. 12.26: RadioButtonTest.vb 2 ' Using RadioButtons to set message window options. 3 4 Public Class FrmRadioButton 5 Inherits System.Windows.Forms.Form 6 7 Private iconType As MessageBoxIcon 8 Private buttonType As MessageBoxButtons 9 10 ' Visual Studio .NET generated code 11 12 ' display message box and obtain dialogue button clicked 13 Private Sub cmdDisplay_Click( ByVal sender _ 14 As System.Object, ByVal e As System.EventArgs) _ 15 Handles cmdDisplay.Click 16 17 Dim dialog As DialogResult = MessageBox.Show( _ 18 &quot;This is Your Custom MessageBox&quot; , &quot;VB&quot; , buttonType, _ 19 iconType) 20 21 ' check for dialog result and display on label 22 Select Case dialog 23 24 Case DialogResult. OK 25 lblDisplay.Text = &quot;OK was pressed&quot; 26 27 Case DialogResult. Cancel 28 lblDisplay.Text = &quot;Cancel was pressed&quot; 29 30 Case DialogResult. Abort 31 lblDisplay.Text = &quot;Abort was pressed&quot; 32 33 Case DialogResult. Retry 34 lblDisplay.Text = &quot;Retry was pressed&quot; 35
  • 40. RadioButtonTest.vb 36 Case DialogResult. Ignore 37 lblDisplay.Text = &quot;Ignore was pressed&quot; 38 39 Case DialogResult. Yes 40 lblDisplay.Text = &quot;Yes was pressed&quot; 41 42 Case DialogResult. No 43 lblDisplay.Text = &quot;No was pressed&quot; 44 End Select 45 46 End Sub ' cmdDisplay_Click 47 48 ' set button type to OK 49 Private Sub radOk_CheckedChanged( ByVal sender _ 50 As System.Object, ByVal e As System.EventArgs) _ 51 Handles radOk.CheckedChanged 52 53 buttonType = MessageBoxButtons. OK 54 End Sub ' radOk_CheckedChanged 55 56 ' set button type to OkCancel 57 Private Sub radOkCancel_CheckedChanged( ByVal sender _ 58 As System.Object, ByVal e As System.EventArgs) _ 59 Handles radOkCancel.CheckedChanged 60 61 buttonType = MessageBoxButtons. OKCancel 62 End Sub ' radOkCancel_CheckedChanged 63 64 ' set button type to AbortRetryIgnore 65 Private Sub radAbortRetryIgnore_CheckedChanged( ByVal sender _ 66 As System.Object, ByVal e As System.EventArgs) _ 67 Handles radAbortRetryIgnore.CheckedChanged 68 69 buttonType = MessageBoxButtons. AbortRetryIgnore 70 End Sub ' radAbortRetryIgnore_CheckedChanged
  • 41. RadioButtonTest.vb 71 72 ' set button type to YesNoCancel 73 Private Sub radYesNoCancel_CheckedChanged( ByVal sender _ 74 As System.Object, ByVal e As System.EventArgs) _ 75 Handles radYesNoCancel.CheckedChanged 76 77 buttonType = MessageBoxButtons. YesNoCancel 78 End Sub ' radYesNoCancel_CheckedChanged 79 80 ' set button type to YesNo 81 Private Sub radYesNo_CheckedChanged( ByVal sender _ 82 As System.Object, ByVal e As System.EventArgs) _ 83 Handles radYesNo.CheckedChanged 84 85 buttonType = MessageBoxButtons. YesNo 86 End Sub ' radYesNo_CheckedChanged 87 88 ' set button type to RetryCancel 89 Private Sub radRetryCancel_CheckedChanged( ByVal sender _ 90 As System.Object, ByVal e As System.EventArgs) _ 91 Handles radRetryCancel.CheckedChanged 92 93 buttonType = MessageBoxButtons. RetryCancel 94 End Sub ' radRetryCancel_CheckedChanged 95 96 ' set icon type to Asterisk when Asterisk checked 97 Private Sub radAsterisk_CheckedChanged( ByVal sender _ 98 As System.Object, ByVal e As System.EventArgs) _ 99 Handles radAsterisk.CheckedChanged 100 101 iconType = MessageBoxIcon. Asterisk 102 End Sub ' radAsterisk_CheckedChanged 103
  • 42. RadioButtonTest.vb 104 ' set icon type to Error when Error checked 105 Private Sub radError_CheckedChanged( ByVal sender _ 106 As System.Object, ByVal e As System.EventArgs) _ 107 Handles radError.CheckedChanged 108 109 iconType = MessageBoxIcon. Error 110 End Sub ' radError_CheckedChanged 111 112 ' set icon type to Exclamation when Exclamation checked 113 Private Sub radExclamation_CheckedChanged( ByVal sender _ 114 As System.Object, ByVal e As System.EventArgs) _ 115 Handles radExclamation.CheckedChanged 116 117 iconType = MessageBoxIcon. Exclamation 118 End Sub ' radExclamation_CheckedChanged 119 120 ' set icon type to Hand when Hand checked 121 Private Sub radHand_CheckedChanged( ByVal sender _ 122 As System.Object, ByVal e As System.EventArgs) _ 123 Handles radHand.CheckedChanged 124 125 iconType = MessageBoxIcon. Hand 126 End Sub ' radHand_CheckedChanged 127 128 ' set icon type to Information when Information checked 129 Private Sub radInformation_CheckedChanged( ByVal sender _ 130 As System.Object, ByVal e As System.EventArgs) _ 131 Handles radInformation.CheckedChanged 132 133 iconType = MessageBoxIcon. Information 134 End Sub ' radInformation_CheckedChanged 135
  • 43. RadioButtonTest.vb 136 ' set icon type to Question when Question checked 137 Private Sub radQuestion_CheckedChanged( ByVal sender _ 138 As System.Object, ByVal e As System.EventArgs) _ 139 Handles radQuestion.CheckedChanged 140 141 iconType = MessageBoxIcon. Question 142 End Sub ' radQuestion_CheckedChanged 143 144 ' set icon type to Stop when Stop checked 145 Private Sub radStop_CheckedChanged( ByVal sender _ 146 As System.Object, ByVal e As System.EventArgs) _ 147 Handles radStop.CheckedChanged 148 149 iconType = MessageBoxIcon. Stop 150 End Sub ' radStop_CheckedChanged 151 152 ' set icon type to Warning when Warning checked 153 Private Sub radWarning_CheckedChanged( ByVal sender _ 154 As System.Object, ByVal e As System.EventArgs) _ 155 Handles radWarning.CheckedChanged 156 157 iconType = MessageBoxIcon. Warning 158 End Sub ' radWarning_CheckedChanged 159 160 End Class ' FrmRadioButtons
  • 48.
  • 49. 12.8   PictureBox es Fig. 12.30 PictureBox properties and events.
  • 50. PictureBoxTest.vb 1 ' Fig. 12.31: PictureBoxTest.vb 2 ' Using a PictureBox to display images. 3 4 Imports System.IO 5 6 Public Class FrmPictureBox 7 Inherits System.Windows.Forms.Form 8 9 Private imageNumber As Integer = -1 10 11 ' Visual Studio.NET generated code 12 13 ' replace image in picImage 14 Private Sub picImage_Click( ByVal sender As System.Object, _ 15 ByVal e As System.EventArgs) Handles picImage.Click 16 17 ' imageNumber from 0 to 2 18 imageNumber = (imageNumber + 1 ) Mod 3 19 20 ' create Image object from file, display in PictureBox 21 picImage.Image = Image.FromFile _ 22 (Directory.GetCurrentDirectory & &quot;magesmage&quot; & _ 23 imageNumber & &quot;.bmp&quot; ) 24 End Sub ' picImage_Click 25 26 End Class ' FrmPictureBox An image object is created from file and set as the PictureBox’s image property
  • 51.  
  • 52.
  • 53. 12.9  Mouse-Event Handling Fig. 12.32 Mouse events, delegates and event arguments.
  • 54. Painter.vb 1 ' Fig. 12.33: Painter.vb 2 ' Using the mouse to draw on a form. 3 4 Public Class FrmPainter 5 Inherits System.Windows.Forms.Form 6 7 Dim shouldPaint As Boolean = False 8 9 ' Visual Studio .NET IDE generated code 10 11 ' draw circle if shouldPaint is True 12 Private Sub FrmPainter_MouseMove( _ 13 ByVal sender As System.Object, _ 14 ByVal e As System.Windows.Forms.MouseEventArgs) _ 15 Handles MyBase.MouseMove 16 17 ' paint circle if mouse pressed 18 If shouldPaint Then 19 Dim graphic As Graphics = CreateGraphics() 20 21 graphic.FillEllipse _ 22 ( New SolidBrush(Color. BlueViolet ), e.X, e.Y, 4 , 4 ) 23 End If 24 25 End Sub ' FrmPainter_MouseMove 26 27 ' set shouldPaint to True 28 Private Sub FrmPainter_MouseDown( ByVal sender As Object, _ 29 ByVal e As System.Windows.Forms.MouseEventArgs) _ 30 Handles MyBase.MouseDown 31 32 shouldPaint = True 33 End Sub ' FrmPainter_MousDown 34 Event handling for Mouse event MouseDown sets variable shouldPaint to True Event handling code begins for event MouseMove
  • 55. Painter.vb 35 ' set shouldPaint to False 36 Private Sub FrmPainter_MouseUp( ByVal sender As Object, _ 37 ByVal e As System.Windows.Forms.MouseEventArgs) _ 38 Handles MyBase.MouseUp 39 40 shouldPaint = False 41 End Sub ' FrmPainter_MouseUp 42 43 End Class ' FrmPainter Event handling for Mouse event MouseUp sets variable shouldPaint to False
  • 56.
  • 57. 12.10 Keyboard-Event Handling Fig. 12.34 Keyboard events, delegates and event arguments.
  • 58. KeyDemo.vb 1 ' Fig. 12.35: KeyDemo.vb 2 ' Displaying information about a user-pressed key. 3 4 Public Class FrmKeyDemo 5 Inherits System.Windows.Forms.Form 6 7 ' Visual Studio.NET generated code 8 9 ' event handler for key press 10 Private Sub FrmKeyDemo_KeyPress( ByVal sender As System.Object, _ 11 ByVal e As System.windows.Forms.KeyPressEventArgs) _ 12 Handles MyBase .KeyPress 13 14 lblCharacter.Text = &quot;Key pressed: &quot; & e.KeyChar 15 End Sub 16 17 ' display modifier keys, key code, key data and key value 18 Private Sub FrmKeyDemo_KeyDown( ByVal sender As System.Object, _ 19 ByVal e As System.Windows.Forms.KeyEventArgs) _ 20 Handles MyBase .KeyDown 21 22 lblInformation.Text = &quot;&quot; 23 24 ' if key is Alt 25 If e.Alt Then 26 lblInformation.Text &= &quot;Alt: Yes&quot; & vbCrLf 27 Else 28 lblInformation.Text &= &quot;Alt: No&quot; & vbCrLf 29 End If 30 KeyDown event handler displays information from its KeyEventArgs object KeyPress event handler accesses the KeyChar property of the KeyPressEventArgs object and displays the Key
  • 59. KeyDemo.vb 31 ' if key is Shift 32 If e.Shift Then 33 lblInformation.Text &= &quot;Shift: Yes&quot; & vbCrLf 34 Else 35 lblInformation.Text &= &quot;Shift: No&quot; & vbCrLf 36 End If 37 38 ' if key is Ctrl 39 If e.Control Then 40 lblInformation.Text &= &quot;Ctrl: Yes&quot; & vbCrLf & _ 41 &quot;KeyCode: &quot; & e.KeyCode.ToString & vbCrLf & _ 42 &quot;KeyData: &quot; & e.KeyData.ToString & vbCrLf & _ 43 &quot;KeyValue: &quot; & e.KeyValue 44 Else 45 lblInformation.Text &= &quot;Ctrl: No&quot; & vbCrLf & _ 46 &quot;KeyCode: &quot; & e.KeyCode.ToString & vbCrLf & _ 47 &quot;KeyData: &quot; & e.KeyData.ToString & vbCrLf & _ 48 &quot;KeyValue: &quot; & e.KeyValue 49 End If 50 51 End Sub ' FrmKeyDemo_KeyDown 52 53 ' clear labels when key is released 54 Private Sub FrmKeyDemo_KeyUp( ByVal sender As System.Object, _ 55 ByVal e As System.windows.Forms.KeyEventArgs) _ 56 Handles MyBase .KeyUp 57 58 lblInformation.Text = &quot;&quot; 59 lblCharacter.Text = &quot;&quot; 60 End Sub ' FrmKeyDemo_KeyUp 61 62 End Class ' FrmKeyDemo The KeyCode property returns a Keys enumeration, which must be converted to a String via method ToString Both labels are cleared when a key is released