473,569 Members | 2,676 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("Remov e",new EventHandler(MI _Click))
};
CM=new ContextMenu(men uItems);

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 2013
Chien Lau <Mo**********@g randson.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("Remov e",new EventHandler(MI _Click))
};
CM=new ContextMenu(men uItems);

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.co m>
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
2383
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 EventHandler(MI_Click)) }; CM=new ContextMenu(menuItems);
2
3868
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 http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it...
2
2123
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 end the program. Clicking the "x" nothing happens and calling this.Close(); when the menu item "close" is pressed also doesn´t change anything. ...
2
1019
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 mycontextmenu.menuitems.Clear, does this dospose of the MenuItems or do I have to still call the Dispose method on each item If I use the ContextMenu.Dispose,...
2
7058
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 operations, the DropdowButton need to clean up all its menuitems, and create new ones. Here the codes: //////////////////// Void...
9
1829
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
1473
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 information. The steps for entering inventory information are: (1) select an existing inventory item from the Select Item ComboBox control, (2) enter the...
4
1018
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 two rows(employee,employee),2-entity/table Definition(no rows),3-attribute name has 2 rows(employee_id,employee_name),4-Attribute/Column Definition...
2
4169
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"> <a href="#" class="menu-item-text"> Menu1 </a>
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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 we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.