this.items = new ToolStripItemCollection (this, items, true);
this.allow_merge = true;
base.AutoSize = true;
+ base.SetAutoSizeMode (AutoSizeMode.GrowAndShrink);
this.back_color = Control.DefaultBackColor;
this.can_overflow = true;
base.CausesValidation = false;
base.TabStop = false;
this.text_direction = ToolStripTextDirection.Horizontal;
this.ResumeLayout ();
- DoAutoSize ();
// Register with the ToolStripManager
ToolStripManager.AddToolStrip (this);
e.Item.Available = true;
e.Item.SetPlacement (ToolStripItemPlacement.Main);
- this.DoAutoSize ();
if (this.Created)
this.PerformLayout ();
protected override void OnLayout (LayoutEventArgs e)
{
- DoAutoSize ();
base.OnLayout (e);
this.SetDisplayedItems ();
// We probably need to redraw for mnemonic underlines
this.Invalidate ();
}
-
- private void DoAutoSize ()
- {
- if (this.AutoSize == true && this.Dock == DockStyle.None) {
- Size new_size = GetToolStripPreferredSize (Size.Empty);
- SetBounds (Left, Top, new_size.Width, new_size.Height, BoundsSpecified.None);
- }
-
- if (this.AutoSize == true && this.Orientation == Orientation.Horizontal && (this.Dock == DockStyle.Top || this.Dock == DockStyle.Bottom))
- SetBounds (Left, Top, Width, GetToolStripPreferredSize (Size.Empty).Height, BoundsSpecified.None);
- }
internal ToolStripItem GetCurrentlySelectedItem ()
{
return null;
}
+
+ internal override Size GetPreferredSizeCore (Size proposedSize)
+ {
+ return GetToolStripPreferredSize (proposedSize);
+ }
internal virtual Size GetToolStripPreferredSize (Size proposedSize)
{
if (this.orientation == Orientation.Vertical) {
foreach (ToolStripItem tsi in this.items)
- if (tsi.GetPreferredSize (Size.Empty).Height + tsi.Margin.Top + tsi.Margin.Bottom > new_size.Height)
- new_size.Height = tsi.GetPreferredSize (Size.Empty).Height + tsi.Margin.Top + tsi.Margin.Bottom;
+ if (tsi.Available) {
+ Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);
+ new_size.Height += tsi_preferred.Height + tsi.Margin.Top + tsi.Margin.Bottom;
+
+ if (new_size.Width < (this.Padding.Horizontal + tsi_preferred.Width))
+ new_size.Width = (this.Padding.Horizontal + tsi_preferred.Width);
+ }
- new_size.Height += this.Padding.Top + this.Padding.Bottom;
- new_size.Width = this.Width;
+ new_size.Height += (this.GripRectangle.Height + this.GripMargin.Vertical + this.Padding.Vertical + 4);
+ return new_size;
} else {
foreach (ToolStripItem tsi in this.items)
if (tsi.Available) {