I am having a problem witth visual studio. I created a menustrip with different menus and some contain separators. I want the theme of the program to be dark so I changed the color of all buttons to black background and white text. however I cannot change the separators' colors. They are white background and black line. I tried from properties - not working. I tried with code - also not working. Can anyone help me? Also I want to ask how to change the color of the outline of the buttons? it's currently white.
Asked
Active
Viewed 1,466 times
0
-
1Possible duplicate of [Change the BackColor of the ToolStripSeparator control](https://stackoverflow.com/questions/15926377/change-the-backcolor-of-the-toolstripseparator-control) – jegtugado Oct 25 '18 at 05:45
2 Answers
3
The default toolstrip renderer ignores the BackColor property and uses hard-coded colors. so write a custom class as below:
public class CustomToolStripSeparator : ToolStripSeparator
{
public CustomToolStripSeparator()
{
Paint += CustomToolStripSeparator_Paint;
}
private void CustomToolStripSeparator_Paint(object sender, PaintEventArgs e)
{
// Get the separator's width and height.
ToolStripSeparator toolStripSeparator = (ToolStripSeparator)sender;
int width = toolStripSeparator.Width;
int height = toolStripSeparator.Height;
//Color foreColor = Color.Blue;
Color backColor = Color.Yellow;
// Fill the background.
e.Graphics.FillRectangle(new SolidBrush(backColor), 0, 0, width, height);
// Draw the line.
//e.Graphics.DrawLine(new Pen(foreColor), 4, height / 2, width - 4, height / 2);
}
}
and inside your form_load method apply your custom toolstripseparator:
private void Form1_Load(object sender, EventArgs e)
{
ToolStripSeparator toolStripSeparator1 = new CustomToolStripSeparator();
ToolStripSeparator toolStripSeparator2 = new CustomToolStripSeparator();
ToolStripSeparator toolStripSeparator3 = new CustomToolStripSeparator();
this.fileToolStripMenuItem.DropDownItems.Add("Save Project");
this.fileToolStripMenuItem.DropDownItems.Add(toolStripSeparator1);
this.fileToolStripMenuItem.DropDownItems.Add("Reload Project");
this.fileToolStripMenuItem.DropDownItems.Add(toolStripSeparator2);
this.fileToolStripMenuItem.DropDownItems.Add("Close Project");
this.fileToolStripMenuItem.DropDownItems.Add(toolStripSeparator3);
this.fileToolStripMenuItem.DropDownItems.Add("New Window");
}

Rashedul.Rubel
- 3,446
- 25
- 36
3
There's no need to create a new separator , just create a color table :
public class MyCustomColors: ProfessionalColorTable
{
public override Color SeparatorLight
{
get { return Color.FromArgb(100, 100, 100); }
}
public override Color SeparatorDark
{
get { return Color.FromArgb(100, 100, 100); }
}
}
}
then use it like :
menu_control.Renderer = new ToolStripProfessionalRenderer(new MyCustomColors());
-
1How do I change just the background of the separator, not the actual line color? Thanks :) – Momoro Feb 05 '21 at 22:49