possible combinations of image and check margins. that has four ToolStripMenuItems showing the four This utility method creates a ContextMenuStrip control G.DrawEllipse(p, new Rectangle(new Point(22, 4), new Size(3, 3))) G.DrawEllipse(p, new Rectangle(new Point(7, 4), new Size(3, 3))) Using (Pen p = new Pen(ProfessionalColors.ButtonPressedBorder)) Graphics g = Graphics.FromImage(sampleBitmap) This utility method creates a Bitmap for use inīitmap sampleBitmap = new Bitmap(32, 32) This is important for correct placement in the z-order. Add the MenuStrip control to the controls collection last. Dock the MenuStrip control to the top of the form. Populate the MenuStrip control with the ToolStripMenuItems. ((ContextMenuStrip)noMargins.DropDown).ShowCheckMargin = false ((ContextMenuStrip)noMargins.DropDown).ShowImageMargin = false NoMargins.DropDown = CreateCheckImageContextMenuStrip() This ToolStripMenuItem has no image and no check margin. ((ContextMenuStrip)checkMarginOnly.DropDown).ShowCheckMargin = true ((ContextMenuStrip)checkMarginOnly.DropDown).ShowImageMargin = false This ToolStripMenuItem has only a check margin.ĬheckMarginOnly.DropDown = CreateCheckImageContextMenuStrip() ((ContextMenuStrip)imageMarginOnly.DropDown).ShowCheckMargin = false ((ContextMenuStrip)imageMarginOnly.DropDown).ShowImageMargin = true ImageMarginOnly.DropDown = CreateCheckImageContextMenuStrip() This ToolStripMenuItem has only an image margin. ((ContextMenuStrip)bothMargins.DropDown).ShowCheckMargin = true ((ContextMenuStrip)bothMargins.DropDown).ShowImageMargin = true This ToolStripMenuItem has an image marginīothMargins.DropDown = CreateCheckImageContextMenuStrip() ToolStripMenuItem noMargins = new ToolStripMenuItem("NoMargins") ToolStripMenuItem checkMarginOnly = new ToolStripMenuItem("CheckMargin") ToolStripMenuItem imageMarginOnly = new ToolStripMenuItem("ImageMargin") ToolStripMenuItem bothMargins = new ToolStripMenuItem("BothMargins") Create the ToolStripMenuItems for the MenuStrip control. This.Text = "ToolStripContextMenuStrip: Image and Check Margins" Size the form to show three wide menu items. and image margins for a ToolStripMenuItem.
This code example demonstrates how to set the check The procedure is the same for a ContextMenuStrip or a MenuStrip. The following code example demonstrates how to set and customize the ContextMenuStrip check margins and image margins.
You can customize a MenuStrip by setting the ShowImageMargin and ShowCheckMargin properties in various combinations.