public Form1() { InitializeComponent(); CustomToolStripMenuItem itemPrimary1 = new CustomToolStripMenuItem("item primary 1"); itemPrimary1.SecondaryContextMenu = new ContextMenuStrip(); itemPrimary1.SecondaryContextMenu.Items.AddRange(new ToolStripMenuItem[] { new ToolStripMenuItem("item primary 1.1"), new ToolStripMenuItem("item primary 1.2"), }); CustomToolStripMenuItem itemPrimary2 = new CustomToolStripMenuItem("item primary 2"); itemPrimary2.DropDownItems.Add("item primary 2, sub 1"); itemPrimary2.DropDownItems.Add("item primary 2, sub 2"); itemPrimary2.SecondaryContextMenu = new ContextMenuStrip(); itemPrimary2.SecondaryContextMenu.Items.AddRange(new ToolStripMenuItem[] { new ToolStripMenuItem("item primary 2.1"), new ToolStripMenuItem("item primary 2.2"), }); CustomContextMenuStrip primaryContextMenu = new CustomContextMenuStrip(); primaryContextMenu.Items.AddRange(new ToolStripItem[] { itemPrimary1, itemPrimary2 }); this.ContextMenuStrip = primaryContextMenu; }
public CustomComboBox() { this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, true); this.SetStyle(ControlStyles.UserMouse, true); this.SetStyle(ControlStyles.UserPaint, true); this.SuspendLayout(); this.ResumeLayout(false); _popupControl = new CustomContextMenuStrip(); _popupControl.BackColor = this.BackColor; _popupControl.Closed += new ToolStripDropDownClosedEventHandler(PopupControl_Closed); _popupControl.ItemClicked += new ToolStripItemClickedEventHandler(PopupControl_ItemClicked); this.Width = DEFAULT_WIDTH; this.Height = DEFAULT_HEIGHT; _selectedItem = null; _bDroppedDown = false; this.BackColor = SystemColors.Control; this.ForeColor = SystemColors.ControlText; _borderColour = SystemColors.ActiveBorder; _dropDownButtonColour = SystemColors.ButtonFace; _droppedDownArrowColour = SystemColors.ControlLight; _closedArrowColour = SystemColors.ControlDark; //Set these via the properties so they take effect on _popupControl this.DropDownBackColour = SystemColors.Control; this.DropDownForeColour = SystemColors.ControlText; this.DropDownBorderColour = SystemColors.ActiveBorder; }