Skip to content

Commit 5d64bba

Browse files
authored
Fix 14062: Refactor StatusStrip DefaultPadding calculation and adjust GripWidth for improved layout consistency (#14068)
Fixes #14062 ## Proposed changes - **GripWidth Adjustment** - Changed GripWidth from 12 to 15 to improve visual balance and reduce unnecessary space. - **Refactored DefaultPadding Logic** - Previous implementation used hardcoded values: Padding(1, 0, 14, 0) or Padding(1, 3, 1, DefaultSize.Height). - New implementation dynamically calculates padding based on `SizingGripBounds.Width` and GripWidth for horizontal orientation, and adjusts for height differences in vertical orientation. - **Update unit test and add StatusStrip to DemoConsole** <!-- We are in TELL-MODE the following section must be completed --> ## Customer Impact - Prevents labels and items from being pushed out of view due to fixed padding values. ## Regression? - Yes
1 parent fd670ec commit 5d64bba

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class StatusStrip : ToolStrip
2020
private static readonly int s_stateSizingGrip = BitVector32.CreateMask();
2121
private static readonly int s_stateCalledSpringTableLayout = BitVector32.CreateMask(s_stateSizingGrip);
2222

23-
private const int GripWidth = 12;
23+
private const int GripWidth = 15;
2424
private const int GripHeight = 22;
2525

2626
private RightToLeftLayoutGrip? _rtlLayoutGrip;
@@ -72,14 +72,22 @@ protected override Padding DefaultPadding
7272
{
7373
if (Orientation == Orientation.Horizontal)
7474
{
75-
return RightToLeft == RightToLeft.No ? new Padding(1, 0, 14, 0) : new Padding(14, 0, 1, 0);
75+
int gripPaddingWidth = SizeGripBounds.Width < GripWidth + 2
76+
? GripWidth + 2
77+
: SizeGripBounds.Width;
78+
return RightToLeft == RightToLeft.No
79+
? new Padding(1, 0, gripPaddingWidth, 0)
80+
: new Padding(gripPaddingWidth, 0, 1, 0);
7681
}
7782
else
7883
{
7984
// vertical
8085
// the difference in symmetry here is that the grip does not actually rotate, it remains the same height it
8186
// was before, so the DisplayRectangle needs to shrink up by its height.
82-
return new Padding(1, 3, 1, DefaultSize.Height);
87+
int gripPaddingHeight = SizeGripBounds.Height < DefaultSize.Height
88+
? DefaultSize.Height
89+
: SizeGripBounds.Height;
90+
return new Padding(1, 3, 1, gripPaddingHeight);
8391
}
8492
}
8593
}

src/test/integration/DesignSurface/DemoConsole/MainForm.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private void CreateDesignSurface(int n)
291291
break;
292292
case 5:
293293
{
294-
rootComponent = surface.CreateRootComponent<Form>(new Size(800, 600));
294+
rootComponent = surface.CreateRootComponent<Form>(new Size(900, 600));
295295
rootComponent.BackColor = Color.Orange;
296296
rootComponent.Text = "Root Component hosted by the DesignSurface N.5";
297297

@@ -309,6 +309,24 @@ private void CreateDesignSurface(int n)
309309
DataGridViewComboBoxColumn comboBoxColumn = surface.CreateComponent<DataGridViewComboBoxColumn>();
310310
comboBoxColumn.HeaderText = "Column1";
311311
dataGridView.Columns.AddRange([comboBoxColumn]);
312+
313+
StatusStrip statusStrip1 = surface.CreateControl<StatusStrip>(new Size(400, 50), new Point(500, 0));
314+
ToolStripStatusLabel toolStripStatusLabel1 = surface.CreateComponent<ToolStripStatusLabel>();
315+
ToolStripStatusLabel toolStripStatusLabel2 = surface.CreateComponent<ToolStripStatusLabel>();
316+
statusStrip1.Dock = DockStyle.Right;
317+
statusStrip1.AutoSize = true;
318+
statusStrip1.SizingGrip = true;
319+
320+
toolStripStatusLabel1.Name = "toolStripStatusLabel1";
321+
toolStripStatusLabel1.Size = new Size(667, 17);
322+
toolStripStatusLabel1.Spring = true;
323+
toolStripStatusLabel1.Text = "toolStripStatusLabel1";
324+
325+
toolStripStatusLabel2.Name = "toolStripStatusLabel2";
326+
toolStripStatusLabel2.Size = new Size(118, 17);
327+
toolStripStatusLabel2.Text = "toolStripStatusLabel2";
328+
329+
statusStrip1.Items.AddRange([toolStripStatusLabel1, toolStripStatusLabel2]);
312330
}
313331

314332
break;

src/test/unit/System.Windows.Forms/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ public static IEnumerable<object[]> StatusStripAccessibleObject_FragmentNavigate
738738
{
739739
Size horizontalOverflowSize = new(70, 30);
740740
Size horizontalOverflowGripSize = new(80, 30);
741-
Size verticalOverflowSize = new(80, 55);
742-
Size verticalOverflowGripSize = new(80, 65);
741+
Size verticalOverflowSize = new(80, 77);
742+
Size verticalOverflowGripSize = new(80, 87);
743743
Size bothOverflowSize = new(70, 25);
744744

745745
yield return new object[] { ToolStripGripStyle.Visible, ToolStripLayoutStyle.HorizontalStackWithOverflow, null, horizontalOverflowGripSize };
@@ -777,8 +777,8 @@ public static IEnumerable<object[]> StatusStripAccessibleObject_FragmentNavigate
777777
{
778778
Size horizontalOverflowSize = new(70, 30);
779779
Size horizontalOverflowGripSize = new(80, 30);
780-
Size verticalOverflowSize = new(30, 55);
781-
Size verticalOverflowGripSize = new(30, 65);
780+
Size verticalOverflowSize = new(30, 77);
781+
Size verticalOverflowGripSize = new(30, 87);
782782
Size bothOverflowSize = new(70, 30);
783783

784784
yield return new object[] { ToolStripGripStyle.Visible, ToolStripLayoutStyle.HorizontalStackWithOverflow, null, horizontalOverflowGripSize };
@@ -820,8 +820,8 @@ public static IEnumerable<object[]> StatusStripAccessibleObject_FragmentNavigate
820820
{
821821
Size horizontalOverflowSize = new(70, 30);
822822
Size horizontalOverflowGripSize = new(80, 30);
823-
Size verticalOverflowSize = new(60, 60);
824-
Size verticalOverflowGripSize = new(70, 70);
823+
Size verticalOverflowSize = new(60, 82);
824+
Size verticalOverflowGripSize = new(70, 92);
825825

826826
yield return new object[] { ToolStripGripStyle.Visible, ToolStripLayoutStyle.HorizontalStackWithOverflow, null, horizontalOverflowGripSize };
827827
yield return new object[] { ToolStripGripStyle.Hidden, ToolStripLayoutStyle.HorizontalStackWithOverflow, null, horizontalOverflowSize };
@@ -933,7 +933,7 @@ static ToolStripItem CreateStatusStripItem()
933933
return new ToolStripStatusLabel()
934934
{
935935
AutoSize = false,
936-
Size = new Size(50, 25)
936+
Size = new Size(40, 25)
937937
};
938938
}
939939
}

src/test/unit/System.Windows.Forms/System/Windows/Forms/StatusStripTests.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ public void StatusStrip_Ctor_Default()
5959
Assert.Equal(Padding.Empty, control.DefaultMargin);
6060
Assert.Equal(Size.Empty, control.DefaultMaximumSize);
6161
Assert.Equal(Size.Empty, control.DefaultMinimumSize);
62-
Assert.Equal(new Padding(1, 0, 14, 0), control.DefaultPadding);
62+
Assert.Equal(new Padding(1, 0, 17, 0), control.DefaultPadding);
6363
Assert.Equal(new Size(200, 22), control.DefaultSize);
6464
Assert.False(control.DefaultShowItemToolTips);
6565
Assert.False(control.DesignMode);
6666
Assert.Empty(control.DisplayedItems);
6767
Assert.Same(control.DisplayedItems, control.DisplayedItems);
68-
Assert.Equal(new Rectangle(1, 0, 185, 22), control.DisplayRectangle);
68+
Assert.Equal(new Rectangle(1, 0, 182, 22), control.DisplayRectangle);
6969
Assert.Equal(DockStyle.Bottom, control.Dock);
7070
Assert.NotNull(control.DockPadding);
7171
Assert.Same(control.DockPadding, control.DockPadding);
7272
Assert.Equal(0, control.DockPadding.Top);
7373
Assert.Equal(0, control.DockPadding.Bottom);
7474
Assert.Equal(1, control.DockPadding.Left);
75-
Assert.Equal(14, control.DockPadding.Right);
75+
Assert.Equal(17, control.DockPadding.Right);
7676
Assert.True(control.DoubleBuffered);
7777
Assert.True(control.Enabled);
7878
Assert.NotNull(control.Events);
@@ -108,13 +108,13 @@ public void StatusStrip_Ctor_Default()
108108
Assert.Equal(Point.Empty, control.Location);
109109
Assert.Equal(Padding.Empty, control.Margin);
110110
Assert.Equal(Size.Empty, control.MaximumSize);
111-
Assert.Equal(new Size(185, 22), control.MaxItemSize);
111+
Assert.Equal(new Size(182, 22), control.MaxItemSize);
112112
Assert.Equal(Size.Empty, control.MinimumSize);
113113
Assert.Equal(Orientation.Horizontal, control.Orientation);
114114
Assert.NotNull(control.OverflowButton);
115115
Assert.Same(control.OverflowButton, control.OverflowButton);
116116
Assert.Same(control, control.OverflowButton.GetCurrentParent());
117-
Assert.Equal(new Padding(1, 0, 14, 0), control.Padding);
117+
Assert.Equal(new Padding(1, 0, 17, 0), control.Padding);
118118
Assert.Null(control.Parent);
119119
Assert.True(control.PreferredSize.Width > 0);
120120
Assert.True(control.PreferredSize.Height > 0);
@@ -136,7 +136,7 @@ public void StatusStrip_Ctor_Default()
136136
Assert.Null(control.Site);
137137
Assert.Equal(new Size(200, 22), control.Size);
138138
Assert.True(control.SizingGrip);
139-
Assert.Equal(new Rectangle(188, 0, 12, 22), control.SizeGripBounds);
139+
Assert.Equal(new Rectangle(185, 0, 15, 22), control.SizeGripBounds);
140140
Assert.True(control.Stretch);
141141
Assert.Equal(0, control.TabIndex);
142142
Assert.False(control.TabStop);
@@ -202,21 +202,21 @@ public void StatusStrip_CanOverflow_Set_GetReturnsExpected(bool value)
202202

203203
public static IEnumerable<object[]> DefaultPadding_Get_TestData()
204204
{
205-
yield return new object[] { ToolStripLayoutStyle.Flow, RightToLeft.Yes, new Padding(14, 0, 1, 0) };
206-
yield return new object[] { ToolStripLayoutStyle.Flow, RightToLeft.No, new Padding(1, 0, 14, 0) };
207-
yield return new object[] { ToolStripLayoutStyle.Flow, RightToLeft.Inherit, new Padding(1, 0, 14, 0) };
205+
yield return new object[] { ToolStripLayoutStyle.Flow, RightToLeft.Yes, new Padding(17, 0, 1, 0) };
206+
yield return new object[] { ToolStripLayoutStyle.Flow, RightToLeft.No, new Padding(1, 0, 17, 0) };
207+
yield return new object[] { ToolStripLayoutStyle.Flow, RightToLeft.Inherit, new Padding(1, 0, 17, 0) };
208208

209-
yield return new object[] { ToolStripLayoutStyle.HorizontalStackWithOverflow, RightToLeft.Yes, new Padding(14, 0, 1, 0) };
210-
yield return new object[] { ToolStripLayoutStyle.HorizontalStackWithOverflow, RightToLeft.No, new Padding(1, 0, 14, 0) };
211-
yield return new object[] { ToolStripLayoutStyle.HorizontalStackWithOverflow, RightToLeft.Inherit, new Padding(1, 0, 14, 0) };
209+
yield return new object[] { ToolStripLayoutStyle.HorizontalStackWithOverflow, RightToLeft.Yes, new Padding(17, 0, 1, 0) };
210+
yield return new object[] { ToolStripLayoutStyle.HorizontalStackWithOverflow, RightToLeft.No, new Padding(1, 0, 17, 0) };
211+
yield return new object[] { ToolStripLayoutStyle.HorizontalStackWithOverflow, RightToLeft.Inherit, new Padding(1, 0, 17, 0) };
212212

213-
yield return new object[] { ToolStripLayoutStyle.StackWithOverflow, RightToLeft.Yes, new Padding(14, 0, 1, 0) };
214-
yield return new object[] { ToolStripLayoutStyle.StackWithOverflow, RightToLeft.No, new Padding(1, 0, 14, 0) };
215-
yield return new object[] { ToolStripLayoutStyle.StackWithOverflow, RightToLeft.Inherit, new Padding(1, 0, 14, 0) };
213+
yield return new object[] { ToolStripLayoutStyle.StackWithOverflow, RightToLeft.Yes, new Padding(17, 0, 1, 0) };
214+
yield return new object[] { ToolStripLayoutStyle.StackWithOverflow, RightToLeft.No, new Padding(1, 0, 17, 0) };
215+
yield return new object[] { ToolStripLayoutStyle.StackWithOverflow, RightToLeft.Inherit, new Padding(1, 0, 17, 0) };
216216

217-
yield return new object[] { ToolStripLayoutStyle.Table, RightToLeft.Yes, new Padding(14, 0, 1, 0) };
218-
yield return new object[] { ToolStripLayoutStyle.Table, RightToLeft.No, new Padding(1, 0, 14, 0) };
219-
yield return new object[] { ToolStripLayoutStyle.Table, RightToLeft.Inherit, new Padding(1, 0, 14, 0) };
217+
yield return new object[] { ToolStripLayoutStyle.Table, RightToLeft.Yes, new Padding(17, 0, 1, 0) };
218+
yield return new object[] { ToolStripLayoutStyle.Table, RightToLeft.No, new Padding(1, 0, 17, 0) };
219+
yield return new object[] { ToolStripLayoutStyle.Table, RightToLeft.Inherit, new Padding(1, 0, 17, 0) };
220220

221221
yield return new object[] { ToolStripLayoutStyle.VerticalStackWithOverflow, RightToLeft.Yes, new Padding(1, 3, 1, 22) };
222222
yield return new object[] { ToolStripLayoutStyle.VerticalStackWithOverflow, RightToLeft.No, new Padding(1, 3, 1, 22) };
@@ -396,7 +396,7 @@ public void StatusStrip_LayoutStyle_Set_GetReturnsExpected(DockStyle dock, ToolS
396396
public static IEnumerable<object[]> Padding_Set_TestData()
397397
{
398398
yield return new object[] { default(Padding), default(Padding), 1, 1 };
399-
yield return new object[] { new Padding(1, 0, 14, 0), new Padding(1, 0, 14, 0), 0, 0 };
399+
yield return new object[] { new Padding(1, 0, 17, 0), new Padding(1, 0, 17, 0), 0, 0 };
400400
yield return new object[] { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 1 };
401401
yield return new object[] { new Padding(1), new Padding(1), 1, 1 };
402402
yield return new object[] { new Padding(-1, -2, -3, -4), Padding.Empty, 1, 2 };
@@ -620,9 +620,9 @@ public static IEnumerable<object[]> SizeGripBounds_Get_TestData()
620620
{
621621
foreach (ToolStripLayoutStyle layoutStyle in Enum.GetValues(typeof(ToolStripLayoutStyle)))
622622
{
623-
yield return new object[] { true, layoutStyle, RightToLeft.Yes, new Rectangle(0, 0, 12, 22) };
624-
yield return new object[] { true, layoutStyle, RightToLeft.No, new Rectangle(188, 0, 12, 22) };
625-
yield return new object[] { true, layoutStyle, RightToLeft.Inherit, new Rectangle(188, 0, 12, 22) };
623+
yield return new object[] { true, layoutStyle, RightToLeft.Yes, new Rectangle(0, 0, 15, 22) };
624+
yield return new object[] { true, layoutStyle, RightToLeft.No, new Rectangle(185, 0, 15, 22) };
625+
yield return new object[] { true, layoutStyle, RightToLeft.Inherit, new Rectangle(185, 0, 15, 22) };
626626
yield return new object[] { false, layoutStyle, RightToLeft.Yes, Rectangle.Empty };
627627
yield return new object[] { false, layoutStyle, RightToLeft.No, Rectangle.Empty };
628628
yield return new object[] { false, layoutStyle, RightToLeft.Inherit, Rectangle.Empty };
@@ -646,9 +646,9 @@ public static IEnumerable<object[]> SizeGripBounds_GetLargeSize_TestData()
646646
{
647647
foreach (ToolStripLayoutStyle layoutStyle in Enum.GetValues(typeof(ToolStripLayoutStyle)))
648648
{
649-
yield return new object[] { true, layoutStyle, RightToLeft.Yes, new Rectangle(0, 10, 12, 22) };
650-
yield return new object[] { true, layoutStyle, RightToLeft.No, new Rectangle(198, 10, 12, 22) };
651-
yield return new object[] { true, layoutStyle, RightToLeft.Inherit, new Rectangle(198, 10, 12, 22) };
649+
yield return new object[] { true, layoutStyle, RightToLeft.Yes, new Rectangle(0, 10, 15, 22) };
650+
yield return new object[] { true, layoutStyle, RightToLeft.No, new Rectangle(195, 10, 15, 22) };
651+
yield return new object[] { true, layoutStyle, RightToLeft.Inherit, new Rectangle(195, 10, 15, 22) };
652652
yield return new object[] { false, layoutStyle, RightToLeft.Yes, Rectangle.Empty };
653653
yield return new object[] { false, layoutStyle, RightToLeft.No, Rectangle.Empty };
654654
yield return new object[] { false, layoutStyle, RightToLeft.Inherit, Rectangle.Empty };
@@ -673,9 +673,9 @@ public static IEnumerable<object[]> SizeGripBounds_GetSmallSize_TestData()
673673
{
674674
foreach (ToolStripLayoutStyle layoutStyle in Enum.GetValues(typeof(ToolStripLayoutStyle)))
675675
{
676-
yield return new object[] { true, layoutStyle, RightToLeft.Yes, new Rectangle(0, 0, 12, 12) };
677-
yield return new object[] { true, layoutStyle, RightToLeft.No, new Rectangle(178, 0, 12, 12) };
678-
yield return new object[] { true, layoutStyle, RightToLeft.Inherit, new Rectangle(178, 0, 12, 12) };
676+
yield return new object[] { true, layoutStyle, RightToLeft.Yes, new Rectangle(0, 0, 15, 12) };
677+
yield return new object[] { true, layoutStyle, RightToLeft.No, new Rectangle(175, 0, 15, 12) };
678+
yield return new object[] { true, layoutStyle, RightToLeft.Inherit, new Rectangle(175, 0, 15, 12) };
679679
yield return new object[] { false, layoutStyle, RightToLeft.Yes, Rectangle.Empty };
680680
yield return new object[] { false, layoutStyle, RightToLeft.No, Rectangle.Empty };
681681
yield return new object[] { false, layoutStyle, RightToLeft.Inherit, Rectangle.Empty };

0 commit comments

Comments
 (0)