ToolStripMenuItem.BackColor not working?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  07 July 2012
ToolStripMenuItem.BackColor not working?

Hi guys,

Has anyone else come across this possible bug with dotNet and ToolStripMenuItem.BackColor not working.

See below for the function that I am using to create the contextMenu and how I am applying the backColor to the MenuItem.
If I try to change any of the other methods it works but this doesn't

fn uI_ContextMenu cmItmArray:Undefined cmAccessArray:Undefined cmImgArray:Undefined cmImgSize:10 cmBgClr:Undefined=(
	if cmItmArray!=Undefined then
		for a=1 to cmItmArray.Count do
			if classOf cmItmArray[a]== Array Then
				append temp_Item_Array temp_Obj
				for b=1 to cmItmArray[a][2].Count do
					temp_Sub_Obj=(dNet_ContextMenu.Items.Get_Item (a-1)).DropDownItems.Add cmItmArray[a][2][b]
					append temp_Sub_Item temp_Sub_Obj
					if cmBgClr!=Undefined do
	-- 							temp_Sub_Obj.Checked=True
						temp_Sub_Obj.BackColor=(dotNetClass "System.Drawing.Color").fromARGB cmBgClr.r cmBgClr.g cmBgClr.b
				append temp_Item_Array temp_Sub_Item
				append cmAccessArray temp_Item_Array
				if cmImgArray!=Undefined do
					for b=1 to cmImgArray[a][2].Count do
				append cmAccessArray temp_Obj
				if cmImgArray!=Undefined do(cmItmArray[a].Image=cmImgArray[a])
		if cmBgClr!=Undefined do
			dNet_ContextMenu.BackColor=(dotNetClass "System.Drawing.Color").Gray
		dNet_ContextMenu.ImageScalingSize=dotNetObject"System.Drawing.Size"cmImgSize cmImgSize
		return dNet_ContextMenu
	)else(Print "No objects have been passed to the context Menu")

Any suggestions would be much appreciated!


  07 July 2012
you can use ToolStripMenuItem Backcolor only in custom drawing mode. In normal paint mode the item's backcolor retrieved from the parent control (menu).
  07 July 2012
here is a sample how to use Paint event to draw an Item:

try(form.Close()) catch()
	global form = dotnetobject "Form"
	form.Text = "RC for Context Menu"
	menu = dotnetobject "ContextMenuStrip"

	i = menu.items.add "File"
	i.BackColor = i.BackColor.Orange
	i.ForeColor = i.ForeColor.Brown

	fn onPaint s e = 
		if not s.Selected then
			bb = dotnetobject "System.Drawing.SolidBrush" s.Backcolor
			fb = dotnetobject "System.Drawing.SolidBrush" s.Forecolor
			bb = dotnetobject "System.Drawing.SolidBrush" s.Backcolor.Green
			fb = dotnetobject "System.Drawing.SolidBrush" s.Forecolor.Yellow
		r = e.ClipRectangle
		e.Graphics.FillRectangle bb r
		sf = dotnetobject "System.Drawing.StringFormat"
		sf.LineAlignment = (dotnetclass "System.Drawing.StringAlignment").Center
		rect = dotnetobject "System.Drawing.RectangleF" (r.x+34) r.y (r.width-34) r.height
		e.Graphics.DrawString s.Text s.Font fb rect sf
	dotnet.addEventHandler i "Paint" onPaint

	menu.items.add "Edit"
	menu.items.add "Exit"

	form.ContextMenuStrip = menu
	MaxHandleWrapper = dotnetobject "MaxCustomControls.Win32HandleWrapper" (dotnetobject "System.IntPtr" (windows.getmaxhwnd()))
	form.Show MaxHandleWrapper
  07 July 2012
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 06:34 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.