1

I want to add a StatusStrip to a UserControl and resize this UserControl at runtime. Here is how I add the 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);

The StatusStrip is displayed at the bottom of the UserControl. However there is no SizingGrip (little Triangle) in the right bottom corner of the StatusStrip. Why not?

4

1 回答 1

3

It's not showing up because a UserControl is not a sizable control at runtime. The StatusStrip, nay more specifically the sizing grip, was built to support the Form control.

Here is the code for ShowSizingGrip, a private property used during paint:

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;
    }
}

at this point I can see two point of interest. First, HandleRef rootHWnd = WindowsFormsUtils.GetRootHWnd(this);, I can't test this class because it's internal, but there's a really good chance it's not going to return a window. However, even if it did, if said window was currently maximized, !UnsafeNativeMethods.IsZoomed(rootHWnd);, the sizing grip wouldn't show either.

My educated guess -- your window is maximized. I make that assumption because it appears Cody Gray was able to make it show up on a UserControl.

于 2013-08-01T12:05:14.753 回答