iamdodge
asked on
Removing checkboxes from menustrip
I'm custom painting a menustrip and all of its toolstripitems and I can't seem to find a way to remove the checkbox/image bit next to the menu items.
I've set everything to only Text but it still wants to display the checkbox area next to all the submenu items and I don't want it there at all.
I've been googling for hours and haven't found "remove menustrip checkboxes" or "remove toolstripitem checkboxes" anywhere.
I've set everything to only Text but it still wants to display the checkbox area next to all the submenu items and I don't want it there at all.
I've been googling for hours and haven't found "remove menustrip checkboxes" or "remove toolstripitem checkboxes" anywhere.
Yeah, I couldn't find that either. I don't even know if there is an option to turn that off.
ASKER
I'm posting some pictures to make sure everyone knows what I'm talking about.
So I've custom painted my menustrips but there's still a background behind them that provides the area where the checkboxes go, and I want that entire area removed.
http://i37.tinypic.com/1zqpjqa.jpg
and when I move my mouse over a piece to highlight it, the background again interferes with my look.
http://i36.tinypic.com/6dycnp.jpg
I want all of that white removed and/or the menu bits should be offset to cover it all up.
I really wish there was some option over in menustrip properties to remove them but I sure haven't found that.
So I've custom painted my menustrips but there's still a background behind them that provides the area where the checkboxes go, and I want that entire area removed.
http://i37.tinypic.com/1zqpjqa.jpg
and when I move my mouse over a piece to highlight it, the background again interferes with my look.
http://i36.tinypic.com/6dycnp.jpg
I want all of that white removed and/or the menu bits should be offset to cover it all up.
I really wish there was some option over in menustrip properties to remove them but I sure haven't found that.
I don't have access to those pictures (filters), so please attach them to this question (Attach File).
Can you show me how you custom paint the menu items?
ASKER
Sure, it's just an override and setting this.menuStrip1.Renderer
I'm sure I need some more stuff in there to remove the white bits but I just don't know how and haven't found how.
I'm sure I need some more stuff in there to remove the white bits but I just don't know how and haven't found how.
private void frmMain_Load(object sender, EventArgs e)
{
this.menuStrip1.Renderer = new CustomProfessionalRenderer();
}
&&
class CustomProfessionalRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
Rectangle r = Rectangle.Inflate(e.AffectedBounds, 0, 0);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(75, 75, 75)), r);
}
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
if (e.Item.Selected)
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150,150,50)), e.Item.ContentRectangle);
}
}
}
Try this:
using System;
using System.Drawing;
using System.Windows.Forms;
internal class CustomProfessionalRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
Rectangle r = Rectangle.Inflate(e.AffectedBounds, 0, 0);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(75, 75, 75)), r);
}
protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red, e.AffectedBounds);
}
protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
{
ToolStripDropDownMenu currentParent = e.Item.GetCurrentParent() as ToolStripDropDownMenu;
int x = currentParent.Padding.Left;
int y = e.Item.Height / 2;
e.Graphics.DrawLine(Pens.White, x, y, e.Item.Bounds.Right, y);
}
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
if (e.Item.Selected)
{
using (SolidBrush brush = new SolidBrush(Color.FromArgb(150, 150, 50)))
{
ToolStripDropDownMenu currentParent = e.Item.GetCurrentParent() as ToolStripDropDownMenu;
if (currentParent != null)
{
Rectangle rect = e.Item.ContentRectangle;
rect.X = currentParent.Padding.Left;
e.Graphics.FillRectangle(brush, rect);
}
}
}
}
}
ASKER
That just made it look like this, which is by all intents and purposes, worse.
The entire white including the underline under the menu name should be gone and the dark bit moved over where all the white (now red ) starts.
new1.PNG
The entire white including the underline under the menu name should be gone and the dark bit moved over where all the white (now red ) starts.
new1.PNG
ASKER
Oops, I forgot selected. Now the selected is a bit better as it just covers the words, but still has that extra to the left.
new2.PNG
new2.PNG
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks!
No, thank you!!