我正在尝试删除在上下文菜单中托管日历控件的toolstripcontrolhost控件周围的空白区域。请参阅随附的图像和代码。
VB:
Dim menuItem As ToolStripMenuItem = New ToolStripMenuItem("MyMenu")
Dim calControl As New MonthCalendar
Dim controlHost As ToolStripControlHost = New ToolStripControlHost(calControl)
controlHost.Margin = Padding.Empty
controlHost.Padding = Padding.Empty
ContextMenuStrip1.Items.Add(menuItem)
menuItem.DropDown.Items.Add(controlHost)
C#:
ToolStripMenuItem menuItem = new ToolStripMenuItem("MyMenu");
MonthCalendar calControl = new MonthCalendar();
ToolStripControlHost controlHost = new ToolStripControlHost(calControl);
controlHost.Margin = Padding.Empty;
controlHost.Padding = Padding.Empty;
ContextMenuStrip1.Items.Add(menuItem);
menuItem.DropDown.Items.Add(controlHost);
最佳答案
在这种情况下,ToolStripDropDown
可能会更好地工作:
MonthCalendar calControl = new MonthCalendar();
ToolStripControlHost controlHost = new ToolStripControlHost(calControl);
controlHost.Margin = Padding.Empty;
controlHost.Padding = Padding.Empty;
ToolStripDropDown toolDrop = new ToolStripDropDown();
toolDrop.Padding = Padding.Emtpy;
toolDrop.Margin = Padding.Empty;
toolDrop.Items.Add(controlHost);
toolDrop.Show(this, location);