How to call a button from a message box (made using a form) in another form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Siobhan Shum
    New Member
    • Feb 2011
    • 4

    #1

    How to call a button from a message box (made using a form) in another form?

    Dear all,

    I am trying to program a dialogue box to appear when the exit button from my 'Login' form is clicked.
    The form has three options; yes, no, cancel.

    The code so far:
    Code:
    ' Cancel button   
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
            Dim mainForm As New DBexit
            DBexit.Show()
            If yes.click = True Then
    
            End If
        End Sub
    The dialogue box is the form called 'DBexit'
    It shows the dialogue box but I am not sure how to proceed to code the buttons from another form into the 'Login' form as the buttons 'yes', 'no' and 'cancel' have not been declared.

    Thank you for your time and help.
  • David Gluth
    New Member
    • Oct 2010
    • 46

    #2
    Try this

    Code:
    Dim mainform As New DBexit
            Select Case mainform.ShowDialog
                Case Is = Windows.Forms.DialogResult.Yes
                    ' do yes option
                Case Is = Windows.Forms.DialogResult.No
                    'do no option
                Case Is = Windows.Forms.DialogResult.Cancel
                    ' do cancel option
                Case Else
                    ' do oops options
            End Select
    Then in dbexit in each button click event set the dialog result
    Code:
    Private Sub btYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btYes.Click
            DialogResult = Windows.Forms.DialogResult.Yes
            Me.Close()
        End Sub

    Comment

    • Siobhan Shum
      New Member
      • Feb 2011
      • 4

      #3
      Thank you very much it worked very well.

      Comment

      Working...