Charan Raj
Charan Raj

Reputation: 481

Toolstripcontrolhost with Toolstripsplitbutton- remove blank spaces

I have recently started using winForms and I am trying to use a panel as a dropdown with ToolStripSplitButton. I wrote a usercontrol (customToolStrip) the inherits toolStrip class and have an extra method as in the code below.

public void AddPanelToSplitButton (Panel panel, ToolStripSplitButton button)
{


    ToolStripControlHost tcHost = new ToolStripControlHost(panel);
    tcHost.Margin = Padding.Empty;
    tcHost.Padding = Padding.Empty;
    tcHost.AutoSize = false;
    tcHost.Size = panel.Size;


    button.DropDown.Size = tcHost.Size;
    button.DropDown.Margin = Padding.Empty;
    button.DropDown.Padding = Padding.Empty;
    button.DropDown.Items.Add(tcHost);
    button.ShowDropDown();
    button.HideDropDown();


}

enter image description here

Could someone please guide me how to remove this white space on either side of the panel.

My requirement is something like this: without white spaces.

enter image description here

Upvotes: 1

Views: 521

Answers (1)

attivid
attivid

Reputation: 36

Try this:

public void AddPanelToSplitButton (Panel panel, ToolStripSplitButton button)
{

ToolStripControlHost tcHost = new ToolStripControlHost(panel);
tcHost.Margin = Padding.Empty;
tcHost.Padding = Padding.Empty;
tcHost.AutoSize = false;
tcHost.Size = panel.Size;

ToolStripDropDown dropDown = new ToolStripDropDown();
dropDown.Items.Add(tcHost);
button.DropDown = dropDown;


}

Upvotes: 2

Related Questions