diff --git a/src/System.Windows.Forms/PublicAPI.Unshipped.txt b/src/System.Windows.Forms/PublicAPI.Unshipped.txt index 3348c917404..4f04d8d271c 100644 --- a/src/System.Windows.Forms/PublicAPI.Unshipped.txt +++ b/src/System.Windows.Forms/PublicAPI.Unshipped.txt @@ -1,3 +1,4 @@ +override System.Windows.Forms.StatusStrip.DisplayRectangle.get -> System.Drawing.Rectangle static System.Windows.Forms.Application.SetColorMode(System.Windows.Forms.SystemColorMode systemColorMode) -> void static System.Windows.Forms.TaskDialog.ShowDialogAsync(nint hwndOwner, System.Windows.Forms.TaskDialogPage! page, System.Windows.Forms.TaskDialogStartupLocation startupLocation = System.Windows.Forms.TaskDialogStartupLocation.CenterOwner) -> System.Threading.Tasks.Task! static System.Windows.Forms.TaskDialog.ShowDialogAsync(System.Windows.Forms.IWin32Window! owner, System.Windows.Forms.TaskDialogPage! page, System.Windows.Forms.TaskDialogStartupLocation startupLocation = System.Windows.Forms.TaskDialogStartupLocation.CenterOwner) -> System.Threading.Tasks.Task! diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs index 7a1b4d7550c..7d9839bd2ad 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs @@ -379,6 +379,7 @@ protected override void SetDisplayedItems() Rectangle lastItemBounds = Rectangle.Empty; ToolStripItem? lastItem = null; + const double HideIntersectionRatioThreshold = 0.5; for (int i = 0; i < Items.Count; i++) { ToolStripItem item = Items[i]; @@ -387,9 +388,36 @@ protected override void SetDisplayedItems() // visible. if (overflow || ((IArrangedElement)item).ParticipatesInLayout) { - if (overflow || (SizingGrip && item.Bounds.IntersectsWith(SizeGripBounds))) + bool hide = false; + + // Check for collisions with SizingGrip when SizingGrip is enabled. + if (!SizeGripBounds.IsEmpty) + { + Rectangle itemBounds = item.Bounds; + + if (itemBounds.IntersectsWith(SizeGripBounds)) + { + Rectangle intersect = Rectangle.Intersect(itemBounds, SizeGripBounds); + double itemArea = Math.Max(1, itemBounds.Width * itemBounds.Height); + double intersectArea = Math.Max(0, intersect.Width * intersect.Height); + double ratio = intersectArea / itemArea; + + // Only hide intersections when the intersection ratio exceeds a threshold, + // otherwise, slight overlap is allowed. + if (ratio >= HideIntersectionRatioThreshold) + { + hide = true; + } + } + } + + if (overflow) + { + hide = true; + } + + if (hide) { - // if the item collides with the size grip, set the location to nomansland. SetItemLocation(item, noMansLand); item.SetPlacement(ToolStripItemPlacement.None); } diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs index b483cce09bd..a1c56c04f3b 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs @@ -933,7 +933,7 @@ static ToolStripItem CreateStatusStripItem() return new ToolStripStatusLabel() { AutoSize = false, - Size = new Size(50, 25) + Size = new Size(40, 25) }; } } diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/StatusStripTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/StatusStripTests.cs index 5931da26e5b..6de09c15ec2 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/StatusStripTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/StatusStripTests.cs @@ -65,7 +65,7 @@ public void StatusStrip_Ctor_Default() Assert.False(control.DesignMode); Assert.Empty(control.DisplayedItems); Assert.Same(control.DisplayedItems, control.DisplayedItems); - Assert.Equal(new Rectangle(1, 0, 185, 22), control.DisplayRectangle); + Assert.Equal(new Rectangle(1, 0, 173, 22), control.DisplayRectangle); Assert.Equal(DockStyle.Bottom, control.Dock); Assert.NotNull(control.DockPadding); Assert.Same(control.DockPadding, control.DockPadding); @@ -108,7 +108,7 @@ public void StatusStrip_Ctor_Default() Assert.Equal(Point.Empty, control.Location); Assert.Equal(Padding.Empty, control.Margin); Assert.Equal(Size.Empty, control.MaximumSize); - Assert.Equal(new Size(185, 22), control.MaxItemSize); + Assert.Equal(new Size(173, 22), control.MaxItemSize); Assert.Equal(Size.Empty, control.MinimumSize); Assert.Equal(Orientation.Horizontal, control.Orientation); Assert.NotNull(control.OverflowButton);