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 CLOSED
 
Thread Tools Search this Thread Display Modes
Old 07 July 2012   #1
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
	(
		dNet_ContextMenu=dotNetObject"System.Windows.Forms.ContextMenuStrip"
		for a=1 to cmItmArray.Count do
		(
			if classOf cmItmArray[a]== Array Then
			(
				temp_Item_Array=#()
				temp_Sub_Item=#()
				temp_Obj=(dNet_ContextMenu.Items.Add(cmItmArray[a][1]))
				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
				(
					cmAccessArray[a][1].Image=cmImgArray[a][1]
					for b=1 to cmImgArray[a][2].Count do
					(
						cmAccessArray[a][2][b].Image=cmImgArray[a][2][b]
					)
				)
			)
			Else
			(
				temp_Obj=(dNet_ContextMenu.Items.Add(cmItmArray[a]))
				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
		dNet_ContextMenu.width=cmImgSize
		return dNet_ContextMenu
	)else(Print "No objects have been passed to the context Menu")
)


Any suggestions would be much appreciated!

Cheers,

Shea.
 
Old 07 July 2012   #2
you can use ToolStripMenuItem Backcolor only in custom drawing mode. In normal paint mode the item's backcolor retrieved from the parent control (menu).
 
Old 07 July 2012   #3
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
		)
		else
		(
			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
)
 
Old 07 July 2012   #4
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 07:12 PM.


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