GUI Concepts -1 - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

GUI Concepts -1

Description:

An event in programming terminology is when something special happens. ... We'll start with all that mysterious code for the Button's Click Event. The Click Event ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 30
Provided by: Wag2
Category:

less

Transcript and Presenter's Notes

Title: GUI Concepts -1


1
GUI Concepts -1

2
Outline
  • Windows Forms
  • Control Properties and Layout
  • TextBoxes
  • GroupBoxes and Panels
  • PictureBoxes
  • CheckBoxes and RadioButtons

3
Windows Forms
4
  Control Properties and Layout
Fig. 12.2 Some basic GUI components.
5
  Control Properties and Layout
The appearance Text property can vary depending
on the context. For example, the text of a
Windows Form is its title bar, but the text of a
button appears on its face.
6
  Control Properties and Layout
  • Method Focus
  • Transfers focus to control
  • Active control
  • Tap index
  • Method Hide
  • Hides control
  • Visible property is false
  • Method Show
  • Shows control
  • Visible property is true

7
  TextBoxes
8
  • ' Fig. 12.18 LabelTextBoxButtonTest.vb
  • ' Using a textbox, label and button to display
    the hidden
  • ' text in a password box.
  • Public Class FrmButtonTest
  • ' handles cmdShow_Click events
  • Private Sub cmdShow_Click(ByVal sender As
    System.Object, _
  • ByVal e As System.EventArgs) Handles
    cmdShow.Click
  • lblOutput.Text txtInput.Text
  • End Sub ' cmdShow_Click
  • End Class ' FrmButtonTest

The password character is set by assigning the
asterisk character () to the PasswordChar
property.
The labels text property is setequal to the
value of the textboxstext property, which was
entered by the user
9
  GroupBoxes and Panels
  • Groupboxes
  • Arrange controls on a GUI
  • Can display captions
  • Do not include scrollbars
  • Panels
  • Arrange controls on a GUI
  • Cannot display captions
  • Include scrollbars

10
   GroupBoxes and Panels
Fig. 12.19 GroupBox properties.
Fig. 12.20 Panel properties.
11
   GroupBoxes and Panels
Fig. 12.21 Creating a Panel with scrollbars.
12
  • 1 ' Fig. 12.22 GroupBoxPanelExample.vb
  • 2 ' Using GroupBoxes and Panels to hold
    buttons.
  • 3
  • 4 Public Class FrmGroupBox
  • 5
  • 6 ' event handlers to change lblMessage
  • 7 Private Sub cmdHi_Click(ByVal sender As
    System.Object, _
  • 8 ByVal e As System.EventArgs) Handles
    cmdHi.Click
  • 9
  • 10 lblMessage.Text "Hi pressed"
  • 11 End Sub ' cmdHi_Click
  • 12
  • 13 ' bye button handler
  • 14 Private Sub cmdBye_Click(ByVal sender As
    System.Object, _
  • 15 ByVal e As System.EventArgs) Handles
    cmdBye.Click
  • 16
  • 17 lblMessage.Text "Bye pressed"
  • 18 End Sub ' cmdBye_Click
  • 19

13
  • 26 ' far right button handler
  • 27 Private Sub cmdRight_Click(ByVal sender
    As System.Object, _
  • 28 ByVal e As System.EventArgs) Handles
    cmdRight.Click
  • 29
  • 30 lblMessage.Text "Far right pressed"
  • 31 End Sub ' cmdRight_Click
  • 32
  • 33 End Class ' FrmGroupBox

14
   PictureBoxes
  • PictureBoxes
  • Display images
  • Bitmap
  • GIF (Graphics Interchange Format)
  • JPEG (Joint Photographic Expert Group)
  • Icons
  • Image property
  • Image to be displayed

15
   PictureBoxes
Fig. 12.30 PictureBox properties and events.
16
  • 1 ' Fig. 12.31 PictureBoxTest.vb
  • 2 ' Using a PictureBox to display images.
  • 3
  • 4 Imports System.IO
  • 5
  • 6 Public Class FrmPictureBox
  • 7
  • 9 Private imageNumber As Integer -1
  • 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
    "\images\image" _

Whenever a user clicks picImage, the image
changes.
To find the images, we use class Directory
(namespace System.IO) method GetCurrentDirectory
We use imageNumber to append the proper number,
enabling us to load either image0, image1 or
image2. The value of Integer imageNumber stays
between 0 and 2 because of the modulus calculation
Class Image has a method FromFile, which takes a
String (the image file) and creates an Image
object.
17
(No Transcript)
18
  CheckBoxes and RadioButtons
  • State Buttons has a state of on/off true/false
  • CheckBoxes
  • Any number can be checked at a time
  • RadioButtons
  • Usually organized in groups and only one checked
    at a time

19
  CheckBoxes and RadioButtons
Fig. 12.23 CheckBox properties and events.
20
  • 1 ' Fig. 12.24 CheckBoxTest.vb
  • 2 ' Using CheckBoxes to toggle italic and bold
    styles.
  • 3
  • 4 Public Class FrmCheckBox
  • 5 ' use Xor to toggle italic, keep other
    styles same
  • 6 Private Sub chkItalic_CheckedChanged _
  • 7 (ByVal sender As System.Object, ByVal e
    As System.EventArgs) _
  • 8 Handles chkItalic.CheckedChanged
  • 9
  • 10 lblOutput.Font New
    Font(lblOutput.Font.Name, _
  • 11 lblOutput.Font.Size,
    lblOutput.Font.Style _
  • 12 Xor FontStyle.Italic)
  • 13 End Sub ' chkItalic_CheckedChanged
  • 14
  • 15 ' use Xor to toggle bold, keep other
    styles same
  • 16 Private Sub chkBold_CheckedChanged
    (ByVal sender As System.Object, _
  • 17 ByVal e As System.EventArgs) Handles
    chkBold.CheckedChanged
  • 18
  • 19 lblOutput.Font New
    Font(lblOutput.Font.Name, _

To enable the font to be changed, the programmer
must set the Font property to a Font object.
The Font constructor that we use takes the font
name, size and style.
The style is a member of the FontStyle
enumeration, which contains the font styles
Regular, Bold, Italic, Strikeout and Underline.
21
(No Transcript)
22
  CheckBoxes and RadioButtons
Fig. 12.25 RadioButton properties and events.
23
  • 1 ' Fig. 12.26 RadioButtonTest.vb
  • 2 ' Using RadioButtons to set message window
    options.
  • 3
  • 4 Public Class FrmRadioButton
  • 5
  • 6 Private iconType As MessageBoxIcon
  • 7 Private buttonType As MessageBoxButtons
  • 8
  • 9 ' display message box and obtain dialogue
    button clicked
  • 10 Private Sub cmdDisplay_Click(ByVal sender
    _
  • 11 As System.Object, ByVal e As
    System.EventArgs) _
  • 12 Handles cmdDisplay.Click
  • 13
  • 14 Dim dialog As DialogResult
    MessageBox.Show( _
  • 15 "This is Your Custom MessageBox",
    "VB", buttonType, _
  • iconType)
  • End Sub ' cmdDisplay_Click
  • ' set button type to OK

24
  • 51 ' set button type to OkCancel
  • 52 Private Sub radOkCancel_CheckedChanged(ByV
    al sender _
  • 53 As System.Object, ByVal e As
    System.EventArgs) _
  • 54 Handles radOkCancel.CheckedChanged
  • 55
  • 56 buttonType MessageBoxButtons.OKCancel
  • 57 End Sub ' radOkCancel_CheckedChanged
  • 58
  • 59 ' set button type to AbortRetryIgnore
  • 60 Private Sub radAbortRetryIgnore_CheckedCha
    nged(ByVal sender _
  • 61 As System.Object, ByVal e As
    System.EventArgs) _
  • 62 Handles radAbortRetryIgnore.CheckedChan
    ged
  • 63
  • 64 buttonType MessageBoxButtons.AbortRetr
    yIgnore
  • 65 End Sub ' radAbortRetryIgnore_CheckedChang
    ed
  • 66 ' set button type to YesNoCancel
  • 67 Private Sub radYesNoCancel_CheckedChanged(
    ByVal sender _
  • 68 As System.Object, ByVal e As
    System.EventArgs) _
  • 69 Handles radYesNoCancel.CheckedChanged

25
  • 73 ' set button type to YesNo
  • 74 Private Sub radYesNo_CheckedChanged(ByVal
    sender _
  • 75 As System.Object, ByVal e As
    System.EventArgs) _
  • 76 Handles radYesNo.CheckedChanged
  • 77
  • 78 buttonType MessageBoxButtons.YesNo
  • 79 End Sub ' radYesNo_CheckedChanged
  • 80
  • 81 ' set button type to RetryCancel
  • 82 Private Sub radRetryCancel_CheckedChanged(
    ByVal sender _
  • 83 As System.Object, ByVal e As
    System.EventArgs) _
  • 84 Handles radRetryCancel.CheckedChanged
  • 85
  • 86 buttonType MessageBoxButtons.RetryCan
    cel
  • 87 End Sub ' radRetryCancel_CheckedChanged
  • 88
  • 89 ' set icon type to Asterisk when Asterisk
    checked
  • 90 Private Sub radAsterisk_CheckedChanged(ByV
    al sender _
  • 91 As System.Object, ByVal e As
    System.EventArgs) _

26
  • 97 ' set icon type to Error when Error
    checked
  • 98 Private Sub radError_CheckedChanged(ByVal
    sender _
  • 99 As System.Object, ByVal e As
    System.EventArgs) _
  • 100 Handles radError.CheckedChanged
  • 101
  • 102 iconType MessageBoxIcon.Error
  • 103 End Sub ' radError_CheckedChanged
  • 104
  • 105 ' set icon type to Exclamation when
    Exclamation checked
  • 106 Private Sub radExclamation_CheckedChanged(
    ByVal sender _
  • 107 As System.Object, ByVal e As
    System.EventArgs) _
  • 108 Handles radExclamation.CheckedChanged
  • 109
  • 110 iconType MessageBoxIcon.Exclamation
  • 111 End Sub ' radExclamation_CheckedChanged
  • 112
  • 113 ' set icon type to Hand when Hand checked
  • 114 Private Sub radHand_CheckedChanged(ByVal
    sender _

27
120 ' set icon type to Information when
Information checked 121 Private Sub
radInformation_CheckedChanged(ByVal sender _ 122
As System.Object, ByVal e As
System.EventArgs) _ 123 Handles
radInformation.CheckedChanged 124 125
iconType MessageBoxIcon.Information 126 End
Sub ' radInformation_CheckedChanged 127 128 '
set icon type to Question when Question
checked 129 Private Sub radQuestion_CheckedCha
nged(ByVal sender _ 130 As System.Object,
ByVal e As System.EventArgs) _ 131 Handles
radQuestion.CheckedChanged 132 133
iconType MessageBoxIcon.Question 134 End
Sub ' radQuestion_CheckedChanged 135 136 '
set icon type to Stop when Stop checked 137
Private Sub radStop_CheckedChanged(ByVal sender
_ 138 As System.Object, ByVal e As
System.EventArgs) _ 139 Handles
radStop.CheckedChanged 140 141 iconType
MessageBoxIcon.Stop 142 End Sub '
radStop_CheckedChanged 143
28
  • 144 ' set icon type to Warning when Warning
    checked
  • 145 Private Sub radWarning_CheckedChanged(ByVa
    l sender _
  • 146 As System.Object, ByVal e As
    System.EventArgs) _
  • 147 Handles radWarning.CheckedChanged
  • 148
  • 149 iconType MessageBoxIcon.Warning
  • 150 End Sub ' radWarning_CheckedChanged
  • 151
  • 152 End Class ' FrmRadioButtons

29
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com