' 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. NoMargins.DropDown = CreateCheckImageContextMenuStrip()ĬType(noMargins.DropDown, ContextMenuStrip).ShowImageMargin = FalseĬType(noMargins.DropDown, ContextMenuStrip).ShowCheckMargin = False ' This ToolStripMenuItem has no image and no check margin. ' This ToolStripMenuItem has only a check margin.ĬheckMarginOnly.DropDown = CreateCheckImageContextMenuStrip()ĬType(checkMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = FalseĬType(checkMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = True ImageMarginOnly.DropDown = CreateCheckImageContextMenuStrip()ĬType(imageMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = TrueĬType(imageMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = False ' This ToolStripMenuItem has only an image margin. ' This ToolStripMenuItem has an image marginīothMargins.DropDown = CreateCheckImageContextMenuStrip()ĬType(bothMargins.DropDown, ContextMenuStrip).ShowImageMargin = TrueĬType(bothMargins.DropDown, ContextMenuStrip).ShowCheckMargin = True ' Create the ToolStripMenuItems for the MenuStrip control.ĭim bothMargins As New ToolStripMenuItem("BothMargins")ĭim imageMarginOnly As New ToolStripMenuItem("ImageMargin")ĭim checkMarginOnly As New ToolStripMenuItem("CheckMargin")ĭim noMargins As New ToolStripMenuItem("NoMargins") Me.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 Add the ToolStripMenuItems to the ContextMenuStrip control.Ĭ(yesCheckYesImage) Ĭ(noCheckYesImage) Ĭ(yesCheckNoImage) Ĭ(noCheckNoImage) New ToolStripMenuItem("No Check, No Image") New ToolStripMenuItem("Check, No Image") check margin and without an image margin. NoCheckYesImage.Image = CreateSampleBitmap() New ToolStripMenuItem("No Check, Image") check margin and with an image margin. YesCheckYesImage.Image = CreateSampleBitmap() Create a new ContextMenuStrip control.ĬontextMenuStrip checkImageContextMenuStrip = new ContextMenuStrip() Internal ContextMenuStrip CreateCheckImageContextMenuStrip() 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |