Displaying a WIndows Form

Dim objMyForm As frmMyForm 

objMyForm = New frmMyForm
If (objMyForm.ShowDialog = WIndows.Forms.DialogResult.OK) Then

End If


DialogResult

This can be used to identify which button was used to close a form.


Private Sub btnStart() Handles btnStart_Click 
   Me.DialogResult = WIndows.Forms.DialogResult.OK
End Sub

Private Sub btnCancel() Handles btnCancel_Click
   Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub



Buttons that return a DialogResult
All buttons have a DialogResult property !!
If you are using the FormClosing event make sure this property is "None" for all buttons.



CancelButton




AcceptButton

If the CancelButton has the focus though pressing Enter will press this button and the AcceptButton is ignored
Always check the TabIndex and make sure this is always the Default OK/Cancel button.



Things to Remember

  • If you change the AcceptButton or the CancelButton property on a windows form the DialogResult property is automatically changed for the button control. If that button is copied and pasted the DialogResult remains intact


© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext