Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoiding the default behaviour

Status
Not open for further replies.

GrigoreDolghin

Programmer
Oct 23, 2000
167
RO
Hello, All.

I am brand new to Visual Basic, and I came from Visual FoxPro. Sincerely, I miss the OOP orientation I have there. I have a lot of questions for you, guys.

Question no. 1:

How can I stop the default behaviour of a control? What I mean: for example, if the user clicks on the right-upper corner of the main form, I want the main form to show a messagebox to confirm the closing, and if the user respond 'Yes', it's ok, but if the user respond 'No', I want to stop the UNLOAD event of the form. Is there a way to do this?

For example, the question no. 2:

How can I create a menu with Alt+letter?


Thank you in advance.

Grigore Dolghin
 
Answer no. 1: ;-)
I snippet code below from my app. I have a MDIForm which will ask users if they click on menu Exit or the little 'x' on the top right corner :

Private Sub MDIForm_Unload(Cancel As Integer)

If MsgBox("Are you sure you want to exit?", _
vbQuestion + vbYesNo, &quot;Confirm Exit Application&quot;) <> vbYes Then Cancel = True

End Sub

Notice every form_unload procedure has 'Cancel As Integer' option. If you don't want to close the form, just set the Cancel value

2. :
Use '&amp;' following by the letter to create a shortcut key.
Ie : E&amp;xit
User can access it by pressing ALT + X.
 
The QueryUnload event is somewhat more appropriate to perform this task, as it offers the opportunity to check why the form unloads.

Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)

where unloadmode can, amongst others, take the following values:

vbFormControlMenu: The user chose the Close command (X button) from the Control Menu.
vbFormCode: The Unload statement is invoked from code.

As stated in an above reply, set the cancel argument to True if you want to stop the closing process _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Hello,

2. :
Use '&amp;' following by the letter to create a shortcut key.
Ie : E&amp;xit
User can access it by pressing ALT + X.


Sorry to bother again. It didn't work. The letter x is underscored, but can be accessed only if the menu is open. Otherwise not. It does not have the same behaviour as CTRL+X, for example. Any thoughts?

Grigore Dolghin

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top