@@ -25,10 +25,11 @@ public partial class ErrorProvider : Component, IExtenderProvider, ISupportIniti
25
25
{
26
26
private readonly Dictionary < Control , ControlItem > _items = new ( ) ;
27
27
private readonly Dictionary < Control , ErrorWindow > _windows = new ( ) ;
28
- private Icon _icon = DefaultIcon ;
28
+ private Icon _icon ;
29
29
private IconRegion ? _region ;
30
30
private int _itemIdCounter ;
31
31
private int _blinkRate ;
32
+ private int _currentDpi ;
32
33
private ErrorBlinkStyle _blinkStyle ;
33
34
private bool _showIcon = true ; // used for blinking
34
35
private bool _inSetErrorManager ;
@@ -314,7 +315,7 @@ public object? DataSource
314
315
{
315
316
if ( _parentControl is not null && _parentControl . BindingContext is not null && value is not null && ! string . IsNullOrEmpty ( _dataMember ) )
316
317
{
317
- // Let's check if the datamember exists in the new data source
318
+ // Let's check if the data member exists in the new data source
318
319
try
319
320
{
320
321
_errorManager = _parentControl . BindingContext [ value , _dataMember ] ;
@@ -552,13 +553,8 @@ private static Icon DefaultIcon
552
553
if ( t_defaultIcon is null )
553
554
{
554
555
// Error provider uses small Icon.
555
- Size LogicalSmallSystemIconSize = OsVersion . IsWindows10_1607OrGreater ( )
556
- ? new (
557
- PInvoke . GetSystemMetricsForDpi ( SYSTEM_METRICS_INDEX . SM_CXSMICON , 96 ) ,
558
- PInvoke . GetSystemMetricsForDpi ( SYSTEM_METRICS_INDEX . SM_CXSMICON , 96 ) )
559
- : new ( 16 , 16 ) ;
560
- using Icon defaultIcon = new ( typeof ( ErrorProvider ) , "Error" ) ;
561
- t_defaultIcon = new Icon ( defaultIcon , LogicalSmallSystemIconSize ) ;
556
+ Icon defaultIcon = new ( typeof ( ErrorProvider ) , "Error" ) ;
557
+ t_defaultIcon = DpiHelper . ScaleSmallIconToDpi ( defaultIcon , DpiHelper . DeviceDpi ) ;
562
558
}
563
559
}
564
560
@@ -576,10 +572,7 @@ private static Icon DefaultIcon
576
572
[ SRDescription ( nameof ( SR . ErrorProviderIconDescr ) ) ]
577
573
public Icon Icon
578
574
{
579
- get
580
- {
581
- return _icon ;
582
- }
575
+ get => _icon ??= DefaultIcon ;
583
576
set
584
577
{
585
578
_icon = value . OrThrowIfNull ( ) ;
@@ -592,10 +585,21 @@ public Icon Icon
592
585
}
593
586
}
594
587
588
+ /// <summary>
589
+ /// Gets or sets the DPI at which the current error is displayed.
590
+ /// If currentDpi is not set, it defaults to _parentControl.DeviceDpi
591
+ /// or the system DPI.
592
+ /// </summary>
593
+ private int CurrentDpi
594
+ {
595
+ get => _currentDpi != 0 ? _currentDpi : _parentControl ? . DeviceDpi ?? DpiHelper . DeviceDpi ;
596
+ set => _currentDpi = value ;
597
+ }
598
+
595
599
/// <summary>
596
600
/// Create the icon region on demand.
597
601
/// </summary>
598
- internal IconRegion Region => _region ??= new IconRegion ( Icon ) ;
602
+ internal IconRegion Region => _region ??= new IconRegion ( Icon , CurrentDpi ) ;
599
603
600
604
/// <summary>
601
605
/// Begin bulk member initialization - deferring binding to data source until EndInit is reached
@@ -769,7 +773,7 @@ internal ErrorWindow EnsureErrorWindow(Control parent)
769
773
[ SRDescription ( nameof ( SR . ErrorProviderIconPaddingDescr ) ) ]
770
774
public int GetIconPadding ( Control control ) => EnsureControlItem ( control ) . IconPadding ;
771
775
772
- private void ResetIcon ( ) => Icon = DefaultIcon ;
776
+ private void ResetIcon ( ) => _icon = null ;
773
777
774
778
[ EditorBrowsable ( EditorBrowsableState . Advanced ) ]
775
779
protected virtual void OnRightToLeftChanged ( EventArgs e )
@@ -814,5 +818,5 @@ public void SetIconPadding(Control control, int padding)
814
818
EnsureControlItem ( control ) . IconPadding = padding ;
815
819
}
816
820
817
- private bool ShouldSerializeIcon ( ) => Icon != DefaultIcon ;
821
+ private bool ShouldSerializeIcon ( ) => _icon is not null && _icon != DefaultIcon ;
818
822
}
0 commit comments