|
-
Sep 20th, 2003, 11:18 PM
#1
Thread Starter
^:^...ANGEL...^:^
Form_Closing
Hi,
I need to find out if the form is closed by control box or by code or by other means. Like in UnloadMode in VB 6.
In VB.NET there is no such thing as UnloadMode and MSDN tells me this.
If it is necessary to determine why the form is closing, you will need to create an overloaded version of the Closing event with custom code to determine the caller.
Cheers.
-
Sep 20th, 2003, 11:32 PM
#2
Thread Starter
^:^...ANGEL...^:^
OK I found this so far and if someone can help me find other constants which are for CloseButton, CloseBYCode and rest then it will be cool.
Thanks.
VB Code:
Const WM_ENDSESSION As Integer = &H16
Dim osexit As Boolean = False
Protected Overrides Sub WndProc(ByRef e As Message)
If (e.Msg = WM_ENDSESSION) Then
osexit = True
Application.Exit()
End If
MyBaseProc(e)
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If osexit Then
'Not doing anything will let the application close
Else
e.Cancel = True 'This will cause the application to ignore the close & continue running
Me.WindowState = FormWindowState.Minimized 'Minimize the Window
End If
End Sub
-
Sep 21st, 2003, 05:31 AM
#3
Thread Starter
^:^...ANGEL...^:^
-
Sep 21st, 2003, 05:48 AM
#4
i cant understand why you need to override ( even if it does say on msdn ) because if you click the X in the form's controlbox , or if you click a button telling a form to close, it will get handled by the Form_Closing sub, are you getting particular problems?
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 21st, 2003, 06:36 AM
#5
Thread Starter
^:^...ANGEL...^:^
So you mean to say that the Closing event is only going to fire up when then X button is clicked but not when the form is closed by code.
Just a little confused. What I need to do is when the X button the clicked I need to hide the form in system tray rather than unloading it.
Cheers.
-
Sep 21st, 2003, 09:28 AM
#6
this is how i use the Form_Closing event ( when the X gets clicked ) , but will also work on say a command button.
VB Code:
[color=blue]Private Sub[/color] Form1_Closing([color=blue]ByVal[/color] sender [color=blue]As Object[/color], [color=blue]ByVal[/color] e [color=blue]As[/color] System.ComponentModel.CancelEventArgs) [color=blue]Handles MyBase[/color].Closing
[color=blue]If[/color] MessageBox.Show("do you want to save your changes before quiting", [color=blue]MyBase[/color][color=black].Name[/color], MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes [color=blue]Then[/color]
e.Cancel = [color=blue]True[/color]
[color=blue]Else[/color]
e.Cancel = [color=blue]False[/color]
[color=blue]End If[/color]
[color=blue]End Sub[/color]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 21st, 2003, 05:54 PM
#7
Thread Starter
^:^...ANGEL...^:^
I don't need any message box. It should straight go to the taskbar.
Cheers.
-
Sep 21st, 2003, 06:25 PM
#8
PowerPoster
Try this, it will allow the user to really close the app if they want, otherwise you can lower it to the toolbar.
VB Code:
Dim fromButton As Boolean = False
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
fromButton = True
Me.Close()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If fromButton Then
'If a person pushes a button on your form to really close it, then
'you would really close the form.
MessageBox.Show("The form is being closed by a button on the form.")
e.Cancel = False
Else
'If a person is closing by the X up top right, then just lower the form
'to the task bar.
MessageBox.Show("The form is being closed another way.")
e.Cancel = True
'Do your code to lower the form to the task bar.
End If
End Sub
-
Sep 21st, 2003, 11:27 PM
#9
Thread Starter
^:^...ANGEL...^:^
Thanks Guyz.
I just used this code and it works nice.
VB Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Show_In_Tray
End Sub
Cheers.
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
|