473,503 Members | 6,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to Dispose() of menu item?

Hi,

Consider the following code where 'CM' is a reference to a ContextMenu:

MenuItem[] menuItems=new MenuItem[]{
new MenuItem("Add",new EventHandler(MI_Click)),
new MenuItem("Remove",new EventHandler(MI_Click))
};
CM=new ContextMenu(menuItems);

In the Dispose() override for my containing form, clearly I'll want to
call Dispose against 'CM'. Must I call Dispose() against the inner MenuItems
that were assigned to 'CM' as well? Does calling CM.Dispose() automatically
Dispose() of the MenuItems that 'CM' contains? I imagine not since the user
may want to reuse these MenuItems for other purposes after the disposal of
CM.

Thanks...
Jul 21 '05 #1
1 2378
Chien Lau <Mo**********@grandson.pop> wrote:
Hi,

Consider the following code where 'CM' is a reference to a ContextMenu:

MenuItem[] menuItems=new MenuItem[]{
new MenuItem("Add",new EventHandler(MI_Click)),
new MenuItem("Remove",new EventHandler(MI_Click))
};
CM=new ContextMenu(menuItems);

In the Dispose() override for my containing form, clearly I'll want to
call Dispose against 'CM'. Must I call Dispose() against the inner MenuItems
that were assigned to 'CM' as well? Does calling CM.Dispose() automatically
Dispose() of the MenuItems that 'CM' contains?
I believe it does.
I imagine not since the user may want to reuse these MenuItems for
other purposes after the disposal of CM.


I think that's going to be a far rarer situation than yours.

You could always check by deriving your own class from MenuItem,
overriding Dispose, adding one to a ContextMenu, and then seeing what
happens if you dispose of the ContextMenu.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3854
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
2
2119
by: Tim Bücker | last post by:
I´ve got a little program with the "x" in the upper right corner and a menu item "close" to do the same - end the program. The problem now is that using my program it gets sometimes impossible to...
1
2011
by: Chien Lau | last post by:
Hi, Consider the following code where 'CM' is a reference to a ContextMenu: MenuItem menuItems=new MenuItem{ new MenuItem("Add",new EventHandler(MI_Click)), new MenuItem("Remove",new...
2
1014
by: Dennis | last post by:
When using a Context Menu, I've added menuitems to the ContextMenu and have the following questions: If I delete a menuitem, do I have to use it's dispose method also? If I use...
2
7053
by: andylotus | last post by:
Hi People I have a WinForm program. The UI contains a ToolStripDropdownButton, which is associate a list of menu items of ToolStripMenuItem, created dynamically. Upon different scenarios of user...
9
1826
by: Academia | last post by:
ContextMenu has a Popup event but MainMenu does not. I need Popup with MainMenu. Do you know anyway to simulate it? Thanks in advance
2
1461
by: redfog | last post by:
I need help writing some code for this procedure: Inventory – Add to Item Listing menu item (15 points). Application users will use this menu as part of the process of entering inventory...
4
1011
by: =?Utf-8?B?Y29uc3RhbnRpbg==?= | last post by:
I know my question seems easy,how to build an array to read the data from Excel worksheet table then load the data into oracle.The table(employee) looks like this have 4 columns:1-entity name with...
2
4157
by: dharmbhav | last post by:
Hello all, I am trying to develop a roll-over menu effect on a page. It works fine with all other browsers except IE6. Can some one please help me? HTML: <div class="menu-item-wrap">...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.