ToolStripDropDownMenu.ShowImageMargin Property

Gets or sets a value indicating whether space for an image is shown on the left edge of the ToolStripMenuItem.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Property ShowImageMargin As Boolean

Property Value

Type: System.Boolean
true if the image margin is shown; otherwise, false. The default is true.

Set the ShowImageMargin property to true to display a graphic image with the ToolStripMenuItem.

The following code example demonstrates how to create and initialize a ContextMenuStrip control by setting the check and image margins. For a full code listing, see How to: Enable Check Margins and Image Margins in ContextMenuStrip Controls.

Public Sub New()
   ' Size the form to show three wide menu items. 
   Me.Width = 500
   Me.Text = "ToolStripContextMenuStrip: Image and Check Margins" 

   ' Create a new MenuStrip control. 
   Dim ms As New MenuStrip()

   ' Create the ToolStripMenuItems for the MenuStrip control. 
   Dim bothMargins As New ToolStripMenuItem("BothMargins")
   Dim imageMarginOnly As New ToolStripMenuItem("ImageMargin")
   Dim checkMarginOnly As New ToolStripMenuItem("CheckMargin")
   Dim noMargins As New ToolStripMenuItem("NoMargins")

   ' Customize the DropDowns menus. 
   ' This ToolStripMenuItem has an image margin  
   ' and a check margin.
   bothMargins.DropDown = CreateCheckImageContextMenuStrip()
   CType(bothMargins.DropDown, ContextMenuStrip).ShowImageMargin = True 
   CType(bothMargins.DropDown, ContextMenuStrip).ShowCheckMargin = True 

   ' This ToolStripMenuItem has only an image margin.
   imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip()
   CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = True 
   CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = False 

   ' This ToolStripMenuItem has only a check margin.
   checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip()
   CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = False 
   CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = True 

   ' This ToolStripMenuItem has no image and no check margin.
   noMargins.DropDown = CreateCheckImageContextMenuStrip()
   CType(noMargins.DropDown, ContextMenuStrip).ShowImageMargin = False 
   CType(noMargins.DropDown, ContextMenuStrip).ShowCheckMargin = False 

   ' Populate the MenuStrip control with the ToolStripMenuItems.
   ms.Items.Add(bothMargins)
   ms.Items.Add(imageMarginOnly)
   ms.Items.Add(checkMarginOnly)
   ms.Items.Add(noMargins)

   ' Dock the MenuStrip control to the top of the form.
   ms.Dock = DockStyle.Top

   ' Add the MenuStrip control to the controls collection last. 
   ' This is important for correct placement in the z-order. 
   Me.Controls.Add(ms)
 End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft