Reputation:
I have searched many times here and on Google looking for a solution that did not envolve utilizing someone's class.
This context menu is pops up where the user right clicks inside a dataGridView
When adding the items the VB code is
Dim m As New ContextMenu()
m.MenuItems.Add(New MenuItem("Disassociate *A* Device"))
m.MenuItems.Add(New MenuItem("Purge Device Assosciations"))
Is there no simple way to reference a resource to add an icon to said menuItems?
Pseudo
m.MenuItem(0).Icon.Source = ....
?
Upvotes: 1
Views: 9475
Reputation: 321
Assuming that this is for a Windows Forms application.
Why not use the ContextMenuStrip?
Example:
Dim m As New ContextMenuStrip()
Dim item As New ToolStripMenuItem("Click Me!")
item.Image = My.Resources.image
m.Items.Add(item)
DataGridView1.ContextMenuStrip = m
Upvotes: 3
Reputation: 1
I use the image propery and assign a system.drawing.image object to it. You wont be able to do it in one line, you do the add once all the properties of the newmenu is set.
Upvotes: 0
Reputation: 6971
You will need to set Owner Draw to true and actually draw the menu item yourself
Here is a good detailed example
Upvotes: 0