This is a rather irritating feature of how VS splits things
up.
Apparently the official way to dispose of component-level
resources when
you're using the designer to design that component is to
add a handler
for your own Disposed event, and dispose of whatever needs
disposing in
there.
The Component class (base class of Form, UserControl, and
pretty much
all design surfaces) raises this event when the component is
disposed.
Barf. But there it is.
--
Ian Griffiths
-----Original Message-----
From: adam
Sent: 01 August 2006 12:24
I have a problem Disposing of objects.
1. Create a new UI component, XXX, in the form designer.
I now have XXX.cs and XXX.Designer.cs
I also have, in XX.Designer.cs this override
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
now in my XXX.cs I create an System.Drawing.Image and I load
it from a
file or whatever.
where do I dispose my image? It's not a Component so I
can't add it to
components. I could create a Component adapter that takes a
disposible
thing, but that seems a bit naff.
Ok maybe the Form.Closing event. well what if XXX inherits
UserControl
and not Form. Am I just supposed to hang off the form
closing event.
Both of these seem a big smelly/hackish
Please let me know if I'm being a nugget.
adam
|