Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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.

Posted

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 Sub

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

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

I don't know why that happens. It doesn't on my test form.

 

Can you post your entire form for us to see?

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted (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 by techmanbd
Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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!)

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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!

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

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

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