2

After some changes, my application started to behave unexpectedly: login form displayed as

If DialogResult.OK <> New frmLogin().ShowDialog() Then ...

is automatically closing itself when line marked as 'problem is included. If I comment in out, it keeps itself open (as it worked before changes) until I call Me.Close()manually.

Private Sub Login_Click()
    If My.Application.appSession.ID > 0 Then
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    Else
        Me.DialogResult = Windows.Forms.DialogResult.Abort 'problem
        MsgBox("Invalid user name or password.", MsgBoxStyle.Critical)
    End If
End Sub

Did you observe described behavior, that purely setting value of DialogResult property closes the dialog?

miroxlav
  • 11,796
  • 5
  • 58
  • 99

1 Answers1

2

To keep the form displayed you need to set it in this way

Me.DialogResult = Windows.Forms.DialogResult.None

Every other settings causes the form to close.

In the form class you could read about the DialogResult property

If the form is displayed as a dialog box, setting this property with a value from the DialogResult enumeration sets the value of the dialog box result for the form, hides the modal dialog box, and returns control to the calling form

Steve
  • 213,761
  • 22
  • 232
  • 286
  • You are right, it was RTFM problem. If you weren't added the answer so quickly, I would have deleted the question. – miroxlav Feb 17 '15 at 11:09
  • Yes it is a simple scenario, nonetheless I think you have expressed well your problem and thus the question could be useful for future readers. – Steve Feb 17 '15 at 11:11
  • Thanks for heads-up. I'll keep it for future reference. – miroxlav Feb 17 '15 at 11:12