|
-
Jun 26th, 2007, 07:39 AM
#1
Thread Starter
Fanatic Member
[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 
-
Jun 26th, 2007, 07:44 AM
#2
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:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
End If
End Sub
-
Jun 26th, 2007, 07:48 AM
#3
Thread Starter
Fanatic Member
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 
-
Jun 26th, 2007, 07:50 AM
#4
Re: Easy close form question (i think!)
VB.NET Code:
Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("Are you sure you want to exit the application?", "Confirm Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Cancel Then
'Don't let the form close.
e.Cancel = True
Exit Sub
End If
End Sub
-
Jun 26th, 2007, 07:56 AM
#5
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....
-
Jun 26th, 2007, 08:01 AM
#6
Thread Starter
Fanatic Member
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 
-
Jun 26th, 2007, 08:21 AM
#7
Re: Easy close form question (i think!)
-
Jun 26th, 2007, 08:23 AM
#8
Thread Starter
Fanatic Member
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 
-
Jun 26th, 2007, 09:08 AM
#9
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
-
Jun 26th, 2007, 09:24 AM
#10
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|