Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My question actually regards Visual Studio 2005 Express.

 

I have a form in my project - created by the desinger and all. It also has a memeber which implements IDisposable, and, because of that, needs to be disposed somehow. The problem is - where do i dispose it?

 

A - ha! why not put the cleanup code in the designer's Dispose() method, you ask? Well, Microsoft chose to put the implementation of the designer aspect of Dispose() in the .Designer.cs. Since it's decalred there, i can't re-decalre it in my .cs file. I would very very much like to avoid editing the .desinger.cs file, for a few reasons:

 

- Editing designer-generated code is usually a BAD idea. When you start messing with the designer's code, the designer can get seriously messed up.

- I hate clicking the "show all files" button. I have to do this because the designer's file is hidden - all the reason why they are not "my" files, and I shouldn't touch them.

 

Can anyone help me in accessing the Dispose() method, without messing with the .designer.cs file?

  • *Gurus*
Posted

He should really still put the code in the Dispose method. Microsoft has chosen to put this method in the .designer file which is hidden in VB (in C# it will be visible, I'm told). However you're still free to edit this file and I don't think the Dispose method gets re-written by designers so your code should remain intact.

 

Also you don't have to click "show all files" to get there - you can just right-click the call to InitializeComponent and choose Go to Definition to load the file.

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
What kind of code would you be putting in your Dispose method? Would you not be able to put this code in either the FormClosed or FormClosing events as these will be called when the form is being destroyed.

I actually thought of that. Putting this kind of code just doesn't feel right, since the events are fired when the form is closed, not disposed (I understand that there's a difference...)

Posted
He should really still put the code in the Dispose method. Microsoft has chosen to put this method in the .designer file which is hidden in VB (in C# it will be visible' date=' I'm told). However you're still free to edit this file and I don't think the Dispose method gets re-written by designers so your code should remain intact.[/quote']Let me see if I get you -

Basically, what you're saying is that there is no way to put my disposal code in the .cs file?

 

Also you don't have to click "show all files" to get there - you can just right-click the call to InitializeComponent and choose Go to Definition to load the file.
I prefer F12 :)

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