Dispose member already defined?

  • Thread starter Thread starter Ole
  • Start date Start date
O

Ole

I have created an user control (that inherits UserControl) in which I have
defined an override on the Dispose member like this:

protected override void Dispose( bool disposing )
{
try
{
blackPen.Dispose();
redPen.Dispose();
bluePen.Dispose();
}
catch
{ }
}

But the compiler complains with the error message:
"The Control" already defines a member called 'Dispose' with the same
parameter

Any clue what could be wrong?

Thanks
Ole
 
Ole,

Well, the compiler error is pretty explicit. Did you look in the
designer generated code? My guess is that is where you will find the method
that the designer created.

If you are storing these pens, and want to get rid of them when
disposing, then I would modify that method to dispose of your pens.

If modifying designer-generated code doesn't sound like a great idea to
you, you could create a class which derives from Component, and then add
that to your form. Then, on that component, you would have an Add method
which would take an IDisposable reference, and in that component's dispose
method, you would cycle through and call Dispose on whatever was added
(which you have to keep a list of internally, of course).
 
Hi Nicholas,

You're absolutely right - why didn't I figure that out - well thanks for
your help!

BR
Ole


Nicholas Paldino said:
Ole,

Well, the compiler error is pretty explicit. Did you look in the
designer generated code? My guess is that is where you will find the
method that the designer created.

If you are storing these pens, and want to get rid of them when
disposing, then I would modify that method to dispose of your pens.

If modifying designer-generated code doesn't sound like a great idea to
you, you could create a class which derives from Component, and then add
that to your form. Then, on that component, you would have an Add method
which would take an IDisposable reference, and in that component's dispose
method, you would cycle through and call Dispose on whatever was added
(which you have to keep a list of internally, of course).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ole said:
I have created an user control (that inherits UserControl) in which I have
defined an override on the Dispose member like this:

protected override void Dispose( bool disposing )
{
try
{
blackPen.Dispose();
redPen.Dispose();
bluePen.Dispose();
}
catch
{ }
}

But the compiler complains with the error message:
"The Control" already defines a member called 'Dispose' with the same
parameter

Any clue what could be wrong?

Thanks
Ole
 
Back
Top