Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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
  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
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.
  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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

  • *Experts*
Posted
Are you using the End statement to close your application? This will completely shut down your application without going through any closing statements.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
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.
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...