Using Dispose Method - System.Windows.Forms  
Author Message
Andrew Mercer





PostPosted: Visual C# General, Using Dispose Method - System.Windows.Forms Top

Hi,

I need to do some closing/cleaning actions when users close a System.Windows.Forms application that I have designed.

However despite a lot of reading I need some clarification.

The user may use a button I have provided or the main window [x]. If they use my button then the process is easier - however I as yet am unable to handle the [x] closing.

I tried adding:

public void Dispose()

{

//Do my stuff

GC.SuppressFinalize(this);

}

But got the following error:

'...Form1.Dispose()' hides inherited member 'System.ComponentModel.Component.Dispose()'. Use the new keyword if hiding was intended.

What am I doing wrong and how can I handle what I am trying to do.

Thanks Andrew




Visual C#3  
 
 
Ken_L





PostPosted: Visual C# General, Using Dispose Method - System.Windows.Forms Top

You're going to kill yourself when you realize how easy this is

In the 1.1 framework you would have gone to the dispose method located in your form1.cs file. In the 2.0 framework you still need to go to the Dispose method but instead of being in your Form1.cs file it is located at Form1.designer.cs file.

The key thing to remind you of is in your code file you see partial class myclass - thus the rest of your class is located somewhere. and that somewhere is the designer.cs file

Good luck!



 
 
Andrew Mercer





PostPosted: Visual C# General, Using Dispose Method - System.Windows.Forms Top

Hi,

Thanks - simple when you know how.

None of the documentation I have read so far explains this...

Andrew