kahlua001 Posted February 10, 2004 Posted February 10, 2004 Hi, I have a form, and when a user navigates away from this form, say open up another program, I want to close my form up. I would do this in the Deactivate sub, but problem is that in this form, I have messageboxes that pop up and when they pop up, they the Deactivate sub gets called. Any way for me to do this with the message boxes? Thanks Quote
Moderators Robby Posted February 10, 2004 Moderators Posted February 10, 2004 I can't see why you're unloading a form in the Deactivate event, you should use Close or Closing events. Quote Visit...Bassic Software
kahlua001 Posted February 10, 2004 Author Posted February 10, 2004 Ok, i should have been more specific. This is actually for a pocket pc app. its a scanner app and I need to close a form when the user goes to another program instead of letting the OS handles mutiple apps running. we are not really using this Pocket PC in the manner it is fashioned to, but its what i have to work with. so how would i determine if a user leaves this form so i can do my closing without mistaking it for a messagebox that pops up? i'm primilary a asp.net developer so i may have some more questions on windows forms, thanks Quote
*Experts* DiverDan Posted February 11, 2004 *Experts* Posted February 11, 2004 It's nice to see a Pocket PC programmer who cares enough not to leave his app running after the user has moved away from it...I really dislike always having to remove them from memory all the time. This will do what you are asking for: Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate End End Sub but wouldn't be nicer and better to simply have and Exit choice in the File menu selections? That way the user knows what is happening, at least I prefer it. Dan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kahlua001 Posted February 11, 2004 Author Posted February 11, 2004 DiverDan, thanks for the code, but how does that handle the messagebox problem? As soon as a message box pops up, this deactivate sub will be called and end the form? Not a desired effect, I only want to end a form when a user truly navigates away from the program. Thanks. Quote
*Experts* DiverDan Posted February 11, 2004 *Experts* Posted February 11, 2004 How is the program going to know the difference? Maybe you can set a flag when your message boxes appear that prevent the form from closing, like maybe Dim CloseProgram as Boolean = True, which will be set to False when the message box opens, and True when the message box is closed. Then in the form Deactive sub call: If CloseProgram then End Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
TechnoTone Posted February 11, 2004 Posted February 11, 2004 This should work: If Not Form.ActiveForm Is Me Then End Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
kahlua001 Posted February 12, 2004 Author Posted February 12, 2004 Ok, Form.Activate doesnt seem to be included in the .Net Compact Framework, so I did the whole boolean variable check. This works, so when I'm in the Deactivate sub I check to see whether there is a messagebox open or not, if there isnt, i then do Me.Close, but as soon as I do so, I get a Dispose error. Can i close my form in a Deactivate sub? Thanks Quote
*Experts* DiverDan Posted February 12, 2004 *Experts* Posted February 12, 2004 Are you using the End statement to close your application? This will completely shut down your application without going through any closing statements. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kahlua001 Posted February 12, 2004 Author Posted February 12, 2004 Nope, .Net Compact does not support End. I guess it really doesnt want me to end an application, it insists on keeping it alive, the best I can do is to close the current form, and kick them back to the login page. Seems that I just cant do it in the deactivate sub. Quote
*Experts* DiverDan Posted February 12, 2004 *Experts* Posted February 12, 2004 How about Me.Close() or Me.Dispose()? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kahlua001 Posted February 12, 2004 Author Posted February 12, 2004 I tried me.close, this is what i in the deactivate If blnMessageBoxExists Then Timer1.Enabled = False Else lblMessage.Text = blnMessageBoxExists Me.Close() End If Now, it would spit out an error no matter if the Me.Close got called or not, as long as it was in the sub. So i commented it out and just checked what the lblMessage.Text was and sure enough, it was False. Thanks for your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.