![]() Create a new ContextMenuStrip control.įruitContextMenuStrip = new ContextMenuStrip() Private ContextMenuStrip fruitContextMenuStrip SourceControl determination with reuse. It also demonstrates dynamic item addition and dynamic This code example demonstrates how to handle the Opening event. The Opening event handler examines the ContextMenuStrip.SourceControl and ToolStripItem.OwnerItem properties and adds a ToolStripItem describing the source control. In the example, an Opening event handler populates the menu item collection. The example also shows how to reuse the same ContextMenuStrip for three different controls on the form. The following code example demonstrates how to dynamically add items to a ContextMenuStrip control. Var dropDownMenu = (ToolStripDropDownMenu) can dynamically populate the menu item collection of a ToolStrip control when the menu opens. The item with text "My Menu" in your sample private void Form_Load(object sender, EventArgs e) In this case, find the DropDown property of your dropdownbutton and cast it to ToolStripDropDownMenu, then set ShowImageMargin property of it to false and BackColor of it to the color you want (blue). ![]() There is also an alternative solution that is applicable if you don't want to use images in your menu items. ToolStripManager.Renderer = new ToolStripProfessionalRenderer(new CustomColorTable()) ![]() Public override Color ToolStripDropDownBackgroundįorm Load Code private void Form_Load(object sender, EventArgs e) Public override Color ImageMarginGradientEnd Public override Color ImageMarginGradientMiddle Public override Color ImageMarginGradientBegin In your Form Load event set Renderer property of ToolStripManager to use a ToolStripProfessionalRenderer that uses your CustomColorTable.ĬustomColorTable Code public class CustomColorTable:ProfessionalColorTable.Override ImageMarginGradientBegin, ImageMarginGradientMiddle, ImageMarginGradientEnd, ToolStripDropDownBackground and return the color you want (blue).from.Create a CustomColorTable class Inheriting from ProfessionalColorTable.Put a ToolStrip on your form and add DropDownButton and its sub items to it, and Set ForeColor of sub items to White.You can do it by implementing your custom color table that inherits ProfessionalColorTable and overriding correct properties. To Change the border color it is enough to follow Plutonix solution that is described in accepted answer.īut to remove that white border between the item and menu border, you should follow one of these solution: Solution 1 You might also change or disable any Theme to see if that might be causing adverse effects. You might also check that you are using a MenuStrip for the menu, Net does have another (older) menu class though you have to go searching to find it. If you are having trouble getting your overrides to work, check that you are using the right ones (or that they mean what the name implies, some are misleading at first). With the mouse over one of the items (mouse not shown), the item uses the MenuItemSelected color which was Consilk. When open, the menu border is Fuschia (mmmm, soothing!) The menu gradient goes from AliceBlue to DodgerBlue an item with the mouse over it uses a top to bottom gradient of LawnGreen to MediumSeaGreen (mouse not shown). (Though, MenuBorder does seem to work no matter what.) Otherwise, results are as expected: The default should be false whether visual styles are enabled or not, but maybe something else has changed it? base.UseSystemColors = false īoth EnableVisualStyles() and UseSystemColors = false have to be in place for all the rendering elements in your color table to be implemented, otherwise only some are used. You may want to also disable system colors as shown in the ctor. You enable visual styles in Main(): // must be done before any UI elements are used If visual styles are not turned on, not all the color table items will be used and some SystemColors will be used instead. ![]() In form load: menuStrip1.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable()) Public override Color MenuStripGradientEnd Public override Color MenuStripGradientBegin Public override Color MenuItemSelectedGradientEnd Public override Color MenuItemSelectedGradientBegin A class which inherits from ProfessionalColorTable works as expected: class MenuColorTable : ProfessionalColorTable Is it possible to change the border color of a toolstrip menu dropdown list.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |