DotNetWebTutor.com                                                    Link to Us

Create your own dialog boxes
You can make your own dialogs

Every form has a showdialog() method

Once a button is clicked the form disappears and dialogresult is passed back
create your own dialog boxes
Example (create your own dialog boxes )

  • create a new project
  • add a second form called dialog.vb
  • drag a button to form1
  • go to the new form(dialog.vb)
  • add label, textbox, 2 buttons like picture below

enter your name
ask for name and OK and cancel button

  • Resize the form to make it smaller
  • Rename the buttons btnOK and btnCancel
  • Name the textbox txtName
  • go into the code for the form

Select the form and click the code button on the solution explorer
code button

  • add this property

readonly property username() as string
get
return txtName.text
end get
end property
read only property

  • select the form and select acceptbutton property, set it to btnOK

btnOK Accept Button

  • set cancelbutton property to cancel button

cancel button

  • click the OK button
  • change dialogresult to OK

dialog result

  • change it to cancel on cancel button

dialog result cancel

  • Open form1.vb
  • Add a button to form1
  • double click button on form1
  • Add this code:

Dim namedialog As New dialog()
If namedialog.ShowDialog = Windows.Forms.DialogResult.OK Then
MessageBox.Show("You clicked Yes and entered "& _ 
namedialog.username)
End If

  • run program

end dialogs