2015-08-20 101 views
1

我最近開始使用winForms,我嘗試使用面板作爲ToolStripSplitButton的下拉菜單。我編寫了一個usercontrol(customToolStrip)繼承toolStrip類,並且具有一個額外的方法,如下面的代碼所示。Toolstripcontrolhost與Toolstripsplitbutton-刪除空格

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

可能有人請指導我如何在面板的兩側刪除此空白。

我的要求是這樣的:沒有空格。

enter image description here

回答

2

試試這個:

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; 


}