Sorry about that. I don't think the example would be useful. Have you
tried to override the onpaint method and draw the text using
Graphics.DrawString?
--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
"rhmware@newsgroups.nospam" <rhmware@newsgroups.nospam> wrote in message
news:154m75i6wo4dh.l6g3yd4i64hz.dlg@40tude.net:
> Sorry about that. I don't think the example would be useful. Have you
> tried to override the onpaint method and draw the text using
> Graphics.DrawString?
Yes. I have tried that but the string gets drawn with the opacity setting
of the menu.
Here is some sample code I have written with a ToolStripRenderer.
It works fine but it seems the menu is also drawing a gray background
behind the transparent background colors that I am drawing. I wonder if
it's possible to prevent the drawing of the gray background.
private void cmdTestScenario_Click(object sender, EventArgs e)
{
System.Windows.Forms.ContextMenuStrip cm = new
ContextMenuStrip();
cm.Renderer = new MyRenderer();
cm.ShowCheckMargin = false;
cm.ShowImageMargin = false;
cm.Items.Add(new ToolStripLabel("Label"));
ToolStripItem it = null;
it = cm.Items.Add("Item1");
it.BackColor = Color.Transparent;
cm.Items.Add("Item2");
cm.Show();
}
private class MyRenderer : ToolStripRenderer
{
protected override void
OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
//draw background with transparent white
Color bgColor = Color.FromArgb(100,Color.Yellow);
Brush b = new SolidBrush(bgColor);
e.Graphics.FillRectangle(b, e.AffectedBounds);
base.OnRenderToolStripBackground(e);
}
protected override void
OnRenderItemBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderItemBackground(e);
}
protected override void
OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
//draw background with transparent white
Color bgColor = Color.FromArgb(100, Color.LightBlue);
Brush b = new SolidBrush(bgColor);
e.Graphics.FillRectangle(b, e.Item.ContentRectangle);
base.OnRenderMenuItemBackground(e);
}
protected override void
OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
//draw with solid red
Color bgColor = Color.Red;
Brush b = new SolidBrush(bgColor);
e.Graphics.DrawString(e.Text,e.TextFont,b,e.TextRectangle);
base.OnRenderItemText(e);
}
Bryan Phillips - 18 Jan 2007 03:09 GMT
Remove the override for OnRenderMenuItemBackground. That is where the
gray looking background is coming from.
Also, I was able to disable the opacity change for the drawstring by NOT
calling base.OnRenderItemText(e); in the override for OnRenderItemText.
The text looks almost crisp. Let me know if this works for you.
--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
"rhmware@newsgroups.nospam" <rhmware@newsgroups.nospam> wrote in message
news:1xs1vvqiqxzue$.3hiiljcqzy44$.dlg@40tude.net:
> > Sorry about that. I don't think the example would be useful. Have you
> > tried to override the onpaint method and draw the text using
[quoted text clipped - 69 lines]
> base.OnRenderItemText(e);
> }
Hans Merkl - 19 Jan 2007 22:31 GMT
Bryan,
I have commented out the calls to the base class but I still don't get
transparency. BTW but I am using Windows 2000.
Can you post your code so I can see what the difference is?
Hans
> Remove the override for OnRenderMenuItemBackground. That is where the
> gray looking background is coming from.
>
> Also, I was able to disable the opacity change for the drawstring by NOT
> calling base.OnRenderItemText(e); in the override for OnRenderItemText.
> The text looks almost crisp. Let me know if this works for you.