Remove .net ContextMenuStrip Padding

Posted by Frosty840 on Stack Overflow See other posts from Stack Overflow or by Frosty840
Published on 2009-03-25T10:22:42Z Indexed on 2010/05/02 12:07 UTC
Read the original article Hit count: 336

Filed under:
|

Hi, When creating a ContextMenuStrip, there is a huge amount of padding around the contained controls. For example:

    Me.myMenu = New ContextMenuStrip
    'unset all obvious padding settings'
    Me.myMenu.ShowCheckMargin = False
    Me.myMenu.ShowImageMargin = False
    Me.myMenu.Margin = New System.Windows.Forms.Padding(0)
    Me.myMenu.Padding = New System.Windows.Forms.Padding(0)

    Dim addButton As New Button
    addButton.Size = New Size(60, 60)
    addButton.Text = "Button"
    Dim addControlHost As New ToolStripControlHost(addButton)

    Me.myMenu.Items.Add(addcontrolhost)

    Me.ContextMenuStrip = Me.myMenu

This, ideally, would cause a 60x60 button to pop up at the cursor location. What actually pops up is this:

The button is there, as expected, but despite there being no margin, no padding, and having set both Show*Margin settings to False, there is a massive border around the Button.

I'm probably missing something blindingly obvious, but how can I get rid of all the white bordering, especially that huge right-hand margin?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about contextmenustrip