DotNetWebTutor.com                                                    Link to Us

Dialogs
Windows Dialogs
Dialog is a special window that pops up to give and/or get info from the user

It is MODAL meaning you cannot interact with other windows while it is shown

Showdialog() method allows you to show a form as modal
The rest of your app stops running until you close this form

Show() method creates a modeless window
Modeless- does not stop code from executing in the rest of your app
messagebox
Messagebox
Messagebox is simplest dialog
Simple Example:
Messagebox.show(“Message here”)

The method is overloaded so you can call it a number of ways
Messagebox.show([message],[dialog caption],[buttons],[icons])

  • Message is a string- message to display
  • Dialog caption-text displayed in title bar
  • Buttons parameter accepts an Enum with following values
    • Messageboxbuttons.abortretryignore
    • Messageboxbuttons.ok
    • Messageboxbuttons.okcancel
    • Messageboxbuttons.retrycancel
    • Messageboxbuttons.yesno
    • Messageboxbuttons.yesnocancel

ok

ok cancel

abort retry ignore

messagebox buttons

yes no

retry cancel

  • Icon also has an enum value
    • Messageboxicon.asterisk
    • Messageboxicon.error
    • Messageboxicon.exclamation
    • Messageboxicon.hand
    • Messageboxicon.information
    • Messageboxicon.none
    • Messageboxicon._question
    • Messageboxicon.stop
    • Messageboxicon.warning

 

It will return an enumerated value in dialogResult telling you the button they clicked

  • dialogResult.ok
  • dialogResult.retry
  • dialogResult.cancel

example of messagebox
Example of messagebox

  • Create a new windows project
  • Go into formclosing event handler

form_closing event

  • Add this code

Dim result as dialogresult

  • Then add this line(all in one line)

Result=messagebox.show(“Close form?”,”quit?”,messageboxbuttons.yesno,messageboxicon.question)

  • Then add the following code:

If result=windows.forms.dialogresult.no then
e.cancel=true
end if
code for messagebox

  • run it

close form?
This code displays a messagebox when you close a form, and if you click No then it cancels the closing of the form.
end messagebox