joe_pool_is Posted February 23, 2004 Posted February 23, 2004 I like users of my program to use the "File | Close" method so that all of my open connections, taskbar icons, etc. can be propperly closed or taken care of. If a user uses the exit button located at the upper-rightmost area of every Window's ... "Window", my exit routine in my program is totally bypassed. I have tried implementing a MyBase.Finalize() and a "Base Class Event > Closing" at separate times, but then things go wrong when my users attempt to close my program properly (i.e. use the "File | Close" technique). Does anyone know how to fix this little thorn in my side? Quote Avoid Sears Home Improvement
TechnoTone Posted February 23, 2004 Posted February 23, 2004 Are you using the Closing event of the form? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
joe_pool_is Posted February 23, 2004 Author Posted February 23, 2004 I tried that with the "Base Class Event > Closing" technique. This works okay if they *only* use the Form's X button to kill the file. If someone tries to use the "File | Close" sub that I wrote (which uses the Me.Close() function), all heck breaks lose. I have even tried calling the Form1.Closing() sub that is created from my "File | Close" sub, but I get unhandled exceptions when I do this. Quote Avoid Sears Home Improvement
*Gurus* divil Posted February 23, 2004 *Gurus* Posted February 23, 2004 The correct way is to listen to the Close event. As long as you just have Close() in your File -> Exit menu event handler, that event will get called either way. "All heck" will not break loose. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
joe_pool_is Posted February 23, 2004 Author Posted February 23, 2004 An icon (called aNotifyIcon in my code) will not be removed from the task bar if I program in the Close() function and my operator clicks the Window's form's exit button. The code was written like this: Private Sub mnuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClose.Click ' // This section has other events to prompt the operator if they ' // would like to do things such as saving any variables to disk. If MyCom.Port.IsOpen Then MyCom.Port.Close() aNotifyIcon.Visible = False Me.Close() End Subbut I am trying to change it to handle all of the closing conditions. Currently, I have this setup: Private Sub mnuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClose.Click ' // This section has other events to prompt the operator if they ' // would like to do things such as saving any variables to disk. Finalize() End Sub ' Protected Overrides Sub Finalize() If MyCom.Port.IsOpen Then MyCom.Port.Close() aNotifyIcon.Visible = False MyBase.Finalize() End Sub but this leaves Visual Studio .NET in the debug mode after the program is stopped. Strange. Do any of you know what is going on? This is perplexing. Quote Avoid Sears Home Improvement
*Gurus* divil Posted February 24, 2004 *Gurus* Posted February 24, 2004 Why are you doing this? I told you, the only thing you need to handle is the Close event. Nothing more. And in your mnuClose_Click event, ONLY put Me.Close(). The notify icon will remove itself correctly. If Visual Studio doesn't exit debug mode, you have other problems. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
joe_pool_is Posted February 24, 2004 Author Posted February 24, 2004 The problem is: The notify icon is *not* going away. This leads me to believe that my other processes (such as closing the COM ports) are also not being done. How can I ensure this is happening? Why is the icon still in my Task Tray when I use the Me.Close() function? How can I debug that? Quote Avoid Sears Home Improvement
TechnoTone Posted February 24, 2004 Posted February 24, 2004 I don't know why that happens. It doesn't on my test form. Can you post your entire form for us to see? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
techmanbd Posted February 24, 2004 Posted February 24, 2004 (edited) This is how I get the X in the corner to do what my exit button does as well actually I needed to edit this private sub mnuEXIT_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEXIT.click me.close end sub Private Sub frmController_unload(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed 'code here. to end what you need, like closing the comport End Sub Edited February 24, 2004 by techmanbd Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
*Gurus* divil Posted February 25, 2004 *Gurus* Posted February 25, 2004 Are you creating the NotifyIcon in code? If you've done it via the designer, it will be added to the components collection of the form and disposed correctly. If you are creating it manually, you'll need to call its Dispose method yourself in the Close event. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
joe_pool_is Posted February 26, 2004 Author Posted February 26, 2004 divil, I think I may be creating the notify icon myself. I have declared it as a global variable in my declarations section as a new NotifyIcon(). Does this mean I have created it with the designer? I'm new to VB and new to the visual programming concept, so some things are taking me a bit to catch on to. Thanks for helping, though. (I *need* it!) Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted February 26, 2004 Administrators Posted February 26, 2004 If you are creating it yourself (sounds like you are) then as Divil said above you wil need to call the .Dispose method of the notify icon in your form's Close event. To create one from the designer - you can drag the notifyIcon from the toolbox on to a form and it will automatically take care of this. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted February 26, 2004 Author Posted February 26, 2004 Freakin' amazing. Really. I've got 4 books on VB.NET and taken two classes on it, and nothing has mentioned anything about being able to drag-and-drop it from the toolbox. I guess it was there the whole time, but I just didn't know to look for it. Thanks for everyone's help. In retrospect, the solution to that whole problem seems elementary. Embarrassing! Quote Avoid Sears Home Improvement
joe_pool_is Posted February 26, 2004 Author Posted February 26, 2004 BTW: Forgot to mention: Divil and PlausiblyDamp were able to fix my problem with the icon in the task tray. Quote Avoid Sears Home Improvement
TechnoTone Posted February 26, 2004 Posted February 26, 2004 Thanks for everyone's help. In retrospect, the solution to that whole problem seems elementary. Embarrassing! You shouldn't wouldn't worry about that. I asked some really simple questions back when I was just getting started on .NET and more often than not the solution was a one-liner. That didn't stop me coming back with more questions. The important thing is that you learn from your experiences. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
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.