Reputation: 481
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();
}
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.
Upvotes: 1
Views: 521
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