Results 1 to 2 of 2

Thread: [Resolved] Being crazy with ShowDialog() and DialogResult

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009

    [Resolved] Being crazy with ShowDialog() and DialogResult

    From the main Form I show a little registration window (frmRegister):

    Private Sub RegisterToolStripMenuItem_Click(sender ....) Handles RegisterToolStripMenuItem.Click
            Dim retVal As DialogResult = frmRegister.ShowDialog()
            Debug.Print("retVal after frmRegister.ShowDialog: " & retVal.ToString)
            If retVal = DialogResult.Cancel Then
            End If
    End Sub
    retVal has to change depending from the btnClose.Text of the frmRegister:

       Private Sub btnClose_Click(ByVal sender ...) Handles btnClose.Click
            If btnClose.Text <> My.Resources.Strings.Close Then
                Me.DialogResult = DialogResult.Cancel
                Me.DialogResult = DialogResult.None
            End If
            Debug.Print("Me.DialogResult before Me.Close code: " & Me.DialogResult.ToString)
            Debug.Print("Me.DialogResult after Me.Close code: " & Me.DialogResult.ToString)
        End Sub
    DialogResult ALWAYS RETURNS CANCEL, even if btnClose.Text = My.Resources.Strings.Close

    The Debug.Print results:

    Me.DialogResult on FrmRegister.Load: None
    Me.DialogResult before Me.Close code: None
    Me.DialogResult after Me.Close code: Cancel
    retVal after frmRegister.ShowDialog: Cancel
    Why Me.Close changes the DialogResult?

    NOTE: all the Buttons of the form are set to DialogResult NONE

    Lol, resolved from myself:
    DialogResult.None IS NOT a DialogResult, so Me.Close generates a DialogResult.Cancel.

    Sobstituted DialogResult.None with DialogResult.OK and all is ok. SORRY mates.
    Last edited by phil2000; Feb 24th, 2018 at 02:12 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: [Resolved] Being crazy with ShowDialog() and DialogResult

    Quote Originally Posted by phil2000 View Post
    DialogResult.None IS NOT a DialogResult, so Me.Close generates a DialogResult.Cancel.
    To be precise, DialogResult.None is the default value but it's not one that will ever be returned when a dialogue closes. It means that there is no result, i.e. the dialogue is still open.

    By the way, there's no point calling Close if you have set the DialogResult property. Setting that property to anything but None will close the dialogue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width