473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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...
Nov 16 '05 #1
1 2007
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
Nov 16 '05 #2

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

Similar topics

1
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
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
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...
2
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.