我想在StatusStrip
添加UserControl
并在运行时调整此UserControl
。以下是我添加StatusStrip
。
StatusStrip sb = new StatusStrip();
sb.BackColor = System.Drawing.SystemColors.ControlDark;
sb.Dock = DockStyle.Bottom;
sb.GripMargin = new Padding(2);
sb.SizingGrip = true;
sb.GripStyle = ToolStripGripStyle.Visible;
sb.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
this.Controls.Add(sb);
StatusStrip
显示在UserControl
的底部。但是SizingGrip
的右下角没有StatusStrip
(小三角形)。为什么不呢?
答案 0 :(得分:3)
它没有显示,因为UserControl
在运行时不是一个相当大的控件。 StatusStrip
,更具体地说是大小调整,是为了支持Form
控件而构建的。
以下是ShowSizingGrip
的代码,在paint期间使用的private
属性:
private bool ShowSizingGrip
{
get
{
if (this.SizingGrip && base.IsHandleCreated)
{
if (base.DesignMode)
{
return true;
}
HandleRef rootHWnd = WindowsFormsUtils.GetRootHWnd(this);
if (rootHWnd.Handle != IntPtr.Zero)
{
return !UnsafeNativeMethods.IsZoomed(rootHWnd);
}
}
return false;
}
}
此时我可以看到两个兴趣点。首先,HandleRef rootHWnd = WindowsFormsUtils.GetRootHWnd(this);
,我无法测试这个类,因为它是internal
,但是很有可能它不会返回窗口。但是,即使它确实如此,如果所述窗口当前最大化!UnsafeNativeMethods.IsZoomed(rootHWnd);
,那么尺寸调整手柄也不会显示。
我有根据的猜测 - 你的窗口最大化了。我做出了这个假设,因为看起来Cody Gray能够让它显示在UserControl
上。