Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
dim array as new list(of picturebox)
dim pic as new picturebox
me.controls.add(pic)
array.add(pic)


i used this code to create picturebox at runtime .now i want to add contextmenu in array of pictureboxes.so i take contextmenustrip in the form with delete(index-0),create(index-1) & create has 5 sub menu.so iused this code.

VB
pic.ContextMenuStrip = ContextMenuStrip1


then i typed code to remove picturebox in "Deletecontextmenustrip_click", me.remove.controls(pic) but i got error.
i tried addhandler with contextmenustrip & called procedure but not working too.


VB
AddHandler pic.ContextMenuStrip.Items(0).Click, AddressOf DeleteToolStripMenuItem_Click


In the procedure i used me.controls.remove(sender)
Posted
Comments
Rajeev Jayaram 28-Jun-12 11:37am    
What is the error message?
Sergey Alexandrovich Kryukov 28-Jun-12 13:24pm    
I don't think it really matters; the right approach should be different -- please see my answer.
--SA
Sergey Alexandrovich Kryukov 28-Jun-12 13:24pm    
It looks like the most usual destiny of the class PictureBox is to be abused by the developers! I cannot believe I came across another way to abuse it. I already answered many questions where the inquirers were pointlessly trying to use this very limiting class for some kind of interactive or animated graphics, which was a wrong approach. Here is a new way to abuse it. On average, the class brought more harm than use... :-)
--SA

1 solution

You should nover use PictureBox with a menu strip. The class System.Windows.Forms.MenuStrip uses quite different approach to present images for menu items. You should use the property ImageList of the type System.Windows.Forms.ImageList instead. Everything is explained here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.menustrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstrip.imagelist.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900