[Closed] .net ContextMenuStrip problem
Hello everyone.
Here I’ve read about some ContextMenuStrip abilities , in this case – displaying icons near the text items (a picture below).
I tryed to use ImageList construction – but without any success…I don’t know about format of the bitmap – it must be a sequense of images or single bitmap divided of icons (like icons for max macroscripts) ? :hmm:
Does anybody use this feature of context menu?
I tried… but .net syntax confused me very much… :banghead:
Here’s a code:
(
arrFavtmp = #(“box”, “Omni”, “Camera”, “Dummy”, “Shape”)
local rendB = ((GetDir #scripts) + “\Image.jpg”)
fn fff sender args = print “oops”
rollout roll_type “” width:131 height:29
(
button btn “Menu”
local contextMenu = dotNetObject “System.Windows.Forms.ContextMenu”
on btn pressed do ——Mouse wheel event (textbox)
(
Vcoors= GetDialogPos roll_type
VSz = GetDialogSize roll_type
contextMenu = dotNetObject “System.Windows.Forms.ContextMenuStrip”
contextMenu.ShowImageMargin = true
imageclass = dotNetclass “System.Drawing.image”
Ilist = dotnetobject “System.Windows.Forms.ImageList”
——- here is something about ImageList, I don’t know exactly what is…
for i =1 to arrFavtmp.count do dotnet.addeventhandler (contextMenu.Items.Add(arrFavtmp[i])) "Click" fff
contextmenu.Show Vcoors[1] (Vcoors[2]+70)
)
)
on execute do createdialog roll_type
)
ps. Sorry for My english
Thanks/
it’s a collection of images stored in <imagelist>.images
You can add an image to that list using <imagelist>.images.add <dotNetImage>, or add a whole range (Array type in maxscript) using <imagelist>.images.addRange <maxScript Array of dotNetImages>.
Alternatively – seeing as you’ll need to work with some maxscript syntax anyway – you could do something like:
menuItem = contextMenu.Items.Add(arrFavtmp[i])
menuItem.image = imageClass.fromFile <bitmap filename>
You can cache that Image object created there so you keep it out of the loop so it doesn’t have to keep re-loading it – e.g. sticking the Image objects into an array that goes with your arrFavtmp labels.
hi Richard,
that’s great!
do you know, by any chance, how i can resize the images in the menu? i can’t get them larger than the default 16×16. every related property seems to be read-only…
try something like this just after creating the contextMenu
contextMenu.ImageScalingSize = dotNetObject "System.Drawing.Size" (width = 64) (height = 64)
works perfectly, thanks!
i would have never figured that out, the whole dotNet stuff is like voodoo to me.
i swear, there is no logic behind it. luckily i “only” need it for UI stuff…