1 / 19

CIS 338: Dialog Boxes

CIS 338: Dialog Boxes. Dr. Ralph D. Westfall April, 2011. 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.

justin
Download Presentation

CIS 338: Dialog Boxes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 File>Open 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)|*.txt|All files (*.*)|*.*" OpenFileDialog1.FileName = "" OpenFileDialog1.ShowDialog() MsgBox(OpenFileDialog1.FileName) End Sub 'notes

  18. Do It Yourself Dialog Boxes • customize a form • add a form: Project>Add Windows Form • set appropriate properties FormBorderStyle = SizableToolWindow '(narrow, just x) (Name) = frm[Name] 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 frm[Name].ShowDialog • can make it to be a template so you can use it again • demo GradeSQL

More Related