diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGrid.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGrid.cs index 161889d3b97..a45d851eb8c 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGrid.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGrid.cs @@ -1753,12 +1753,19 @@ private PropertyGridToolStripButton CreatePushButton( EventHandler eventHandler, bool useRadioButtonRole = false) { + // ToolStripItem/ToolStripButton bake Margin and the minimum button width from + // ScaleHelper.InitialSystemDpi (the process's startup DPI) at construction time. Re-apply both + // explicitly so a button (re)created after a runtime DPI change reflects the grid's actual current + // DPI; DeviceDpi routes through ToolStripButton's own existing, correct DeviceDpi setter override. + // See https://github.com/dotnet/winforms/issues/8268. PropertyGridToolStripButton button = new(this, useRadioButtonRole) { Text = toolTipText, AutoToolTip = true, DisplayStyle = ToolStripItemDisplayStyle.Image, - ImageIndex = imageIndex + ImageIndex = imageIndex, + Margin = ScaleHelper.ScaleToDpi(new Padding(0, 1, 0, 2), DeviceDpi), + DeviceDpi = DeviceDpi }; button.Click += eventHandler; @@ -2106,7 +2113,7 @@ private void EnsureLargeButtons() ImageSize = s_largeButtonSize }; - if (ScaleHelper.IsScalingRequired) + if (ScaleHelper.IsScalingRequirementMet) { AddLargeImage(_alphaBitmap); AddLargeImage(_categoryBitmap); @@ -2140,7 +2147,7 @@ private void EnsureLargeButtons() } } - // This method should be called only inside a if (DpiHelper.IsScalingRequired) clause. + // This method should be called only inside a if (ScaleHelper.IsScalingRequirementMet) clause. private void AddLargeImage(Bitmap? originalBitmap) { if (originalBitmap is null) @@ -3874,7 +3881,7 @@ private void SetupToolbar(bool fullRebuild) { _normalButtonImages?.Dispose(); _normalButtonImages = new ImageList(); - if (ScaleHelper.IsScalingRequired) + if (ScaleHelper.IsScalingRequirementMet) { _normalButtonImages.ImageSize = s_normalButtonSize; } @@ -4013,6 +4020,9 @@ private void SetupToolbar(bool fullRebuild) _toolStrip.ImageList = LargeButtons ? _largeButtonImages : _normalButtonImages; + // Covers LargeButtons only (_largeButtonImages isn't ready earlier); a no-op otherwise. + _toolStrip.ImageScalingSize = _toolStrip.ImageList!.ImageSize; + using (SuspendLayoutScope scope = new(_toolStrip)) { _toolStrip.Items.Clear();