View Full Version : Visualk Basic: how do i control the X button
athalonxpkid
03-04-02, 11:40 PM
how do i controll the X button thats in the top left corner of any program. for instance how would i make a message box appear when the X was clicked.
Normally you'd just test for WM_CLOSE in your message handling loop, but short of subclassing..... In vb what you'd have to do is put the message box code in your form's "terminate", "unload", or "queryunload" event. Any one of those should work.
athalonxpkid
03-05-02, 06:11 PM
uhh i dont understand how to control them in any way, i just know of unload (form name)
a little more help
.....alright.
Open up the visual basic ide, and start a blank project. Now double click on "Form1". This takes you into the "code" window. You'll see something like "Private sub Form_Load()" or something like that. On the upper right hand side of the screen you'll see a combo box that says "Load". If you scroll through that combo box you'll see other words like "paint", "mousemove", etc. The reason that you saw "Load" at first and that vb automatically started the "Form_Load" event procedure for you is that's the default event for a from. ...just like if you had added a command button to your form and double clicked it, you'd see "Private sub Command1_click".....because the "click" event is the default event for the command button in vb.
So there's also a combo box on the left (when you're in the "code" window). That's how you select what control you want to deal with. The combo box on the right is how you select which event you want to deal with for the control that is selected in the left combo box.
So select "Form1" on the left combo box, and select "terminate" on the right combo box. Then you should see the following in the code window:
"Private Sub Form1_Terminate()
xxxxxxx <---handle your message box in here
End Sub"
And pretty please......go to your local library, find a visual basic book, check it out, and read it. You'll find yourself with less grey hairs that way.
athalonxpkid
03-06-02, 12:26 AM
i have many VB books, but i didnt kniw where too look specificly for the X button thingy in those. thanx a lot
athalonxpkid
03-06-02, 12:29 AM
the only thing is, how do i stop the program from exitting if i click "no, i dont want to exit", in my msgbox
athalonxpkid
03-06-02, 12:31 AM
nevermind, i got it to work.... now if i only knew how to close this thread
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.