c# - Change backcolor of ToolstripSeparator in submenue? -


this question has answer here:

i have contextmenustrip has 4 items. 1 of items has submenu 4 items, o 1 separator. changed color items separator's backcolor not change

why , how change it?

thispic

i've faced problem today , found it's pretty simple solve it.

having same situation:

enter image description here

solution:

create class inherits toolstripseparator class , add method paint eventhandler draw separator:

public class extendedtoolstripseparator : toolstripseparator {     public extendedtoolstripseparator()     {         this.paint += extendedtoolstripseparator_paint;     }      private void extendedtoolstripseparator_paint(object sender, painteventargs e)     {         // separator's width , height.         toolstripseparator toolstripseparator = (toolstripseparator)sender;         int width = toolstripseparator.width;         int height = toolstripseparator.height;          // choose colors drawing.         // i've used color.white forecolor.         color forecolor = color.fromname(utilities.constants.controlsrelatedconstants.standardforecolorname);         // color.teal backcolor.         color backcolor = color.fromname(utilities.constants.controlsrelatedconstants.standardbackcolorname);          // fill background.         e.graphics.fillrectangle(new solidbrush(backcolor), 0, 0, width, height);          // draw line.         e.graphics.drawline(new pen(forecolor), 4, height / 2, width - 4, height / 2);     } } 

then add separator:

toolstripseparator toolstripseparator = new extendedtoolstripseparator();  this.dropdownitems.add(newgametoolstripmenuitem); this.dropdownitems.add(addplayertoolstripmenuitem); this.dropdownitems.add(viewresultstoolstripmenuitem); // add separator here. this.dropdownitems.add(toolstripseparator); this.dropdownitems.add(exittoolstripmenuitem); 

result:

enter image description here


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -