经过一些更改后,我的应用程序开始出现意外行为:登录表单显示为
If DialogResult.OK <> New frmLogin().ShowDialog() Then ...
当包含标记为“问题”的行时自动关闭。如果我注释掉,它会保持自身打开状态(因为它在更改之前有效),直到我手动调用 Me.Close()
。
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
您是否观察到所描述的行为,即纯粹设置 DialogResult
属性的值会关闭对话框?
最佳答案
要保持表单显示,您需要这样设置
Me.DialogResult = Windows.Forms.DialogResult.None
所有其他设置都会导致表单关闭。
在表单类中,您可以阅读有关 DialogResult 的信息。属性
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
关于.net - DialogResult 关闭设置对通过 ShowDialog() 显示的表单有影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28560356/