Results 1 to 10 of 10

Thread: [RESOLVED] Easy close form question (i think!)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Resolved [RESOLVED] Easy close form question (i think!)

    Hi guys,

    This is probably a really easy question to answer but i can't seem to find the answer for myself! lol

    I'm using .net cf and i was just wondering whether there was an event that captured if the x at the top right hand corner of a form has been tapped to close a form? I have tried using the forms closed and closing but neither of them are fired when the x is clicked.

    Thanks in advance for any help
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: Easy close form question (i think!)

    I don't know if this is in the CF but is how i would do it in full version

    vb Code:
    1. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    2.     Handles Me.FormClosing
    3.  
    4.         If e.CloseReason = CloseReason.UserClosing Then
    5.  
    6.  
    7.         End If
    8.  
    9.     End Sub
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Easy close form question (i think!)

    Thanks for the quick reply, but closereason isn't available in the compact framework.

    Thanks anyways
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Easy close form question (i think!)

    VB.NET Code:
    1. Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    2.                If MessageBox.Show("Are you sure you want to exit the application?", "Confirm Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Cancel Then
    3.             'Don't let the form close.
    4.             e.Cancel = True
    5.             Exit Sub
    6.  
    7.         End If
    8.     End Sub

  5. #5
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: Easy close form question (i think!)

    Does that distinguish between the different reasons for exiting though?

    I mean, Kimmy might want to exit the application without them having the chance to cancel the process although i guess you could have a boolean value and use it to differentiate who exactly is doing the closing....
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Easy close form question (i think!)

    The reason i want to capture this isn't to close an application.

    What i have is a little message system and i have an inbox with some labels that have the sender and subject of a message. Now when the user clicks on a label it brings up another form with the full message on and i have to menu options, one to delete or reply to the message and another to close the message. Now if the user clicks the close menu option then a procedure is called to mark the message as read and do some other stuff and i want the same thing to happen when the x is clicked at the top of the screen so i need to capture that event and i cant find anythin that ONLY handles that.

    I hope this makes things a little clearer. If you do need anymore information then just ask and i'll provide what you need.

    Thanks again
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  7. #7
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Easy close form question (i think!)

    Is this 2005 or 2003?
    VB 2005, Win Xp Pro sp2

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Easy close form question (i think!)

    2005.....sorry thought i'd specified!
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  9. #9
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Easy close form question (i think!)

    The closing event fires in the CF, but you are not getting it because the form is not closing. I am sure you know that, but just as a reminder, the X button of a form does not close it - it minimizes it.

    The OK button closes it, to use it instead of the X, set the form's MinimizeBox property to false. It is counterintuitive but it's the default. I always close my forms instead of minimizing them in order to save resources.

    Now to answer the question, the minimize event is actually the Deactivate event. If you have an X use:
    Code:
        Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
    
            MessageBox.Show("Minimizing")
    
            ''stop it from minimizing or do whatever you need
            'Me.Activate()
        End Sub
    If you have an OK, the closing event will fire.
    Code:
        Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    
            MessageBox.Show("Closing")
    
            ''stop it from closing
            'e.Cancel = True
    
        End Sub
    Last edited by Half; Jun 26th, 2007 at 09:12 AM. Reason: Grammar!
    VB 2005, Win Xp Pro sp2

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Easy close form question (i think!)

    Yeah i was aware that it minimizes it which is why i knew i couldn't use the closing or closed events. I think my best option is to just set the controlbox to false to make sure that they do always use the close menu option at the bottom of the screen.

    Thanks everyone for their input
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width