CIS 338: Dialog Boxes - PowerPoint PPT Presentation

Loading...

PPT – CIS 338: Dialog Boxes PowerPoint presentation | free to download - id: 6f967a-NjU0Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

CIS 338: Dialog Boxes

Description:

CIS 338: Dialog Boxes Dr. Ralph D. Westfall April, 2011 – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 20
Provided by: Ralp134
Learn more at: http://www.cpp.edu
Category:
Tags: cis | boxes | dialog

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: CIS 338: Dialog Boxes


1
CIS 338 Dialog Boxes
  • Dr. Ralph D. Westfall
  • April, 2011

2
Dialog Boxes
  • do one of following
  • display a message to user
  • has only one button (OK)
  • get a decision from user
  • OK, Cancel, etc.
  • get information from user
  • e.g., name, password, age, date of birth, etc.

3
VB Dialog Boxes You Can Use
  • MessageBox
  • message one or more buttons
  • MsgBox
  • simplified version of MessageBox
  • User-created
  • do it yourself with forms, or
  • using form templates

4
Syntax Convention
  • computer language documentation uses a syntax
    convention to show which items are required
    versus optional
  • MessageBox.Show(prompt , title, buttons ,
    icon, defaultButton, options)
  • items in square brackets are optional
  • prompt is the only required argument in the above
    code
  • commas not needed for unused options, so are
    shown inside square brackets

5
MessageBox
  • MessageBox.Show(prompt , title, buttons ,
    icon, defaultButton, options)
  • prompt text string to display
  • title message box title bar (same as Project
    name if not provided)
  • buttons button(s) to display
  • icon icon (image)
  • defaultButton gets initial (at 1st) focus
  • options international settings
  • Note MsgBox has an abbreviated syntax

6
Message Box Examples
  • MessageBox.Show("It's crashing")
  • 'using a string literal
  • sMessage "The 3rd crash today!"
  • MessageBox.Show(sMessage)
  • 'using a string variable
  • nReply MessageBox.Show("Quit?",_
  • MessageBoxButtons.YesNo)
  • 'using MessageBox as a function
  • 'that receives a return value
  • 'note object.property .YesNo

7
MessageBoxIcon Values
  • values in the MessageBoxIcon property that get
    specified icons
  • .Stop (or .Error) 'severe error
  • .Exclamation 'warning
  • .Question 'need information
  • .Information 'status message
  • .None (or no value) 'no icon (default)
  • 'more in notes

8
MessageBox Button Values
  • properties control number of choices and text on
    buttons
  • .OK (OK button)
  • .OKCancel (2 buttons)
  • .AbortRetryIgnore (3 buttons)
  • .YesNoCancel (3 buttons)
  • .YesNo (2 buttons)
  • .RetryCancel (2 buttons)

9
MessageBoxDefaultButton Values
  • identify default button (gets the focus) counting
    from the left
  • .Button1
  • .Button2
  • .Button3
  • for example, .Button2 on a YesNo button makes No
    the default

10
MessageBox Button Values
  • vbOK 1
  • vbCancel 2
  • vbYesNo 4
  • vbIgnore 5
  • vbYes 6
  • vbNo 7 'notes
  • nReply MessageBox.Show("Choice?", "Click",
    MessageBoxButtons.YesNo)
  • If nReply vbYes Then some code

11
Modal MessageBoxes
  • MessageBoxes are "modal" at the application level
  • until clicks button, user can't do anything else
    in the VB application
  • no other VB code can run until clicked
  • VB6 can also make modal for whole system
  • will not be able to use any other program in
    Windows until the user responds to the MessageBox
    (was NOT a good idea!)

12
InputBox Dialog Control
  • syntax
  • InputBox(prompt, title,default,x,y)
  • nInput InputBox("Age?")
  • prompt is shown above text input box
  • if provided, title shows on title bar
  • default goes into the input box (e.g., "guest")
  • x (horizontal), y (vertical) position of box on
    screen (in pixels)

13
InputBox Dialog Example
  • Dim sName As String
  • sName InputBox("Enter your name", _
  • " Name?", "guest", 50, 50)
  • 'guest is the default value in this code

14
More Dialog Controls
  • can also use Microsoft Common Dialog controls in
    VB.NET
  • standard Windows/Microsoft Office items
  • Color, Folder, Font, File Open/Save items in
    Toolbox
  • may need to stretch ToolBox to see them (down
    toward the bottom in Dialogs category)

15
Using Common Dialog Boxes
  • drag and drop onto the form, but will only see in
    new panel under the form
  • OpenFileDialog files to open
  • SaveFileDialog files to save
  • FontDialog fonts to use
  • ColorDialog colors to use
  • PrintDialog is now in a separate section of
    Toolbox with other printing objects

16
Example FileDialog
  • shows a standard Windows FilegtOpen form
  • code specifies separate lines of text in Files of
    type
  • dropdown ComboBox at bottom of dialog
  • just returns name of file selected by user
  • still need to write code to open/read file

17
FileDialog Code
  • Private Sub Button2_Click( etc.
  • OpenFileDialog1.InitialDirectory "C\"
  • OpenFileDialog1.Filter() "Text files
    (.txt).txtAll files (.)."
  • OpenFileDialog1.FileName ""
  • OpenFileDialog1.ShowDialog()
  • MsgBox(OpenFileDialog1.FileName)
  • End Sub 'notes

18
Do It Yourself Dialog Boxes
  • customize a form
  • add a form ProjectgtAdd Windows Form
  • set appropriate properties
  • FormBorderStyle SizableToolWindow '(narrow,
    just x)
  • (Name) frmName
  • Text whatever you want to say

19
Do It Yourself Dialog Boxes - 2
  • can customize it to do what you want
  • add labels and buttons, etc. as appropriate
  • display modally when you need it
  • frmName.ShowDialog
  • can make it to be a template so you can use it
    again
  • demo GradeSQL
About PowerShow.com