PDA

View Full Version : .net ContextMenuStrip problem


SECC0
04-01-2009, 07:02 PM
Hello everyone.

Here (http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx) 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/

ZeBoxx2
04-02-2009, 10:38 AM
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.

SECC0
04-02-2009, 11:10 AM
Thank you, Richard!
I' ll try it :wip:

plastic
05-07-2009, 02:31 PM
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 16x16. every related property seems to be read-only...

ZeBoxx2
05-07-2009, 03:43 PM
try something like this just after creating the contextMenu

contextMenu.ImageScalingSize = dotNetObject "System.Drawing.Size" (width = 64) (height = 64)

plastic
05-07-2009, 08:55 PM
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...

CGTalk Moderation
05-07-2009, 08:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.