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?
i've faced problem today , found it's pretty simple solve it.
having same situation:
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:
Comments
Post a Comment