The form object has a Close method that, as its name indicates, closes the form. Since this is the only form in the project (other than the message box which will close when the user chooses the Yes or No button), closing the form ends the a pplication as well. However, we only want to close the form if the application user chose Yes, not if the application user chose No.
The following code closes the form if, and only if, the application user's choice was Yes: If drQuit = DialogResult.Yes Then Me.Close() End If
This code statement first compares the value of drQuit and DialogResult.Yes using the If keyword. If the user chose Yes, the value of drQuit is DialogResult.Yes, so the comparison drQuit = DialogResult.Yes will be true and the Me.Close() statement is executed. However, if the user chose No, the value of drQuit is DialogResult.No, so the comparison drQuit = DialogResult.Yes will be false and the Me.Close() statement will not be executed.
Was this article helpful?