|
|
|
date: Sun, 20 Jul 2008 19:17:27 -0600,
group: microsoft.public.dotnet.framework.windowsforms.controls
back
RE: free'ing up controls
Hi Dave,
When we add a component on a form, we should always add it to the
components of the form to make sure that the component will be disposed in
time when the form is closed.
FYI, when a form is closed, the form will call the Dispose method on itself
which in turn invokes the protected Dispose(bool) method with the disposing
parameter set to true. When the disposing parameter is true, this method
releases all resources held by any managed objects that this Form
references. This method invokes the Dispose method of each referenced
object.
If you'd like to remove a component from a form before the form is closed,
you need to remove it from the components of the form first and then call
the Dispose method on the component to release the resource this component
is using and set the component to null at last to make it out of scope.
When we add a control on a form, we add it to the Controls collection of
the form. When the form is closed, the form will call the Dispose method on
each control in the Controls collection automatically.
If you'd like to remove a control from a form before the form is closed,
you need to remove it from the Controls collection of the form first and
then call the Dispose method on the control to release the resource this
control is using and set the control to null at last to make it out of
scope.
Although the ContextMenuStrip inherits from the Control class, if you add a
ContextMenuStrip on a form at design time, the form designer adds it to the
components of the form rather than the Controls collection. So you may
treat the ContextMenuStrip as a component when you add/remove it from a
from.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Mon, 21 Jul 2008 04:04:59 GMT
author: (Linda Liu[MSFT])
Re: free'ing up controls
Hi;
Thank you - this was exactly what I needed to know.
One follow-on question, as MenuContextStrip is a Control that is
treated as a Component, is there a list of what goes in which so I
know where to add them and where to look for them.
Also, does the MenuCOntextStrip constructor put it in the form's
components or do I need to add it after I create it?
thanks - dave
On Mon, 21 Jul 2008 04:04:59 GMT, v-lliu@online.microsoft.com (Linda
Liu[MSFT]) wrote:
>Hi Dave,
>
>When we add a component on a form, we should always add it to the
>components of the form to make sure that the component will be disposed in
>time when the form is closed.
>
>FYI, when a form is closed, the form will call the Dispose method on itself
>which in turn invokes the protected Dispose(bool) method with the disposing
>parameter set to true. When the disposing parameter is true, this method
>releases all resources held by any managed objects that this Form
>references. This method invokes the Dispose method of each referenced
>object.
>
>If you'd like to remove a component from a form before the form is closed,
>you need to remove it from the components of the form first and then call
>the Dispose method on the component to release the resource this component
>is using and set the component to null at last to make it out of scope.
>
>When we add a control on a form, we add it to the Controls collection of
>the form. When the form is closed, the form will call the Dispose method on
>each control in the Controls collection automatically.
>
>If you'd like to remove a control from a form before the form is closed,
>you need to remove it from the Controls collection of the form first and
>then call the Dispose method on the control to release the resource this
>control is using and set the control to null at last to make it out of
>scope.
>
>Although the ContextMenuStrip inherits from the Control class, if you add a
>ContextMenuStrip on a form at design time, the form designer adds it to the
>components of the form rather than the Controls collection. So you may
>treat the ContextMenuStrip as a component when you add/remove it from a
>from.
>
>Hope this helps.
>If you have any question, please feel free to let me know.
>
>Sincerely,
>Linda Liu
>Microsoft Online Community Support
david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
date: Mon, 21 Jul 2008 14:40:21 -0600
author: David Thielen am
Re: free'ing up controls
Hi Dave,
Thank you for your reply!
> as MenuContextStrip is a Control that is treated as a Component, is there
a list of what goes in which so I know where to add them and where to look
for them.
No, there isn't such a list. I do more research and find that the reason
why the form designer treats the ContextMenuStrip as a component is that
the ContextMenuStrip is a top-level control and it cannot be added to the
Controls collection of the form.
Nevertheless, if you don't find a Control in the Controls collection of the
form, it should be in the components of the form.
> does the MenuCOntextStrip constructor put it in the form's components or
do I need to add it after I create it?
Yes, it's the constructor of the ContextMenuStrip that puts the
ContextMenuStrip in the form's components. You can also create an instance
of ContextMenuStrip without a parameter and then add the instance to the
components of the form.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Tue, 22 Jul 2008 01:07:07 GMT
author: (Linda Liu[MSFT])
|
|