我正在尝试删除在contexttru中托管日历控件的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);
答案 0 :(得分:1)
在这种情况下,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);
答案 1 :(得分:0)
试试这个
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);
ToolStripDropDown dropDown = new ToolStripDropDown();
dropDown.Items.Add(controlHost);
menuItem.DropDown = dropDown;
答案 2 :(得分:0)
此问题的大多数答案我发现重定向开发人员使用上下文菜单条的ToolStripDropDown
INSTEAD 。但是,对于我的项目,我想要从已经很复杂的上下文菜单中删除。在我的项目早期,对于需要的不同弹出窗口,我从这里得到了一个简单的弹出包装器:http://www.codeproject.com/Articles/17502/Simple-Popup-Control。这个简单的弹出窗口继承自ToolStripDropDown
。这是核心VB代码:
Public Class PopupBox
Inherits ToolStripDropDown
Private mHost As ToolStripControlHost = Nothing
Public ReadOnly Property Host As ToolStripControlHost
Get
Return mHost
End Get
End Property
Public Sub New(content As Control)
MyBase.New()
Me.ResizeRedraw = True
Me.Margin = Padding.Empty
Me.Padding = Padding.Empty
Me.AutoSize = True
Me.mHost = New ToolStripControlHost(content)
Me.mHost.Margin = Padding.Empty
Me.mHost.Padding = Padding.Empty
Me.mHost.AutoSize = True
Me.Items.Add(Me.mHost)
End Sub
End Class
事实证明,这个弹出窗口非常适合用于将下拉列表(没有填充)应用于现有的上下文菜单。以下是步骤:
ToolStripMenuItem
将。在此示例中,该项目命名为&#34; ToolStripMenuItem1&#34;。 ToolStripMenuItem1.DropDown = New PopupBox(<your control here>)
显然没有继承的对象访问受保护的ResizeRedraw
属性并将所述值应用于{{的构造函数中的Margin
,Padding
和AutoSize
属性1}},PopupBox
仍然在下拉列表的左侧和右侧应用填充。所以没有捷径。
注意:CodeProject文章指出GNU License,并且PopupBox可以托管的内容有一些警告,请阅读文章了解更多详情。
相关/来源链接: