@@ -4546,6 +4546,7 @@ protected virtual void OnDpiChanged(DpiChangedEventArgs e)
4546
4546
_processingDpiChanged = true ;
4547
4547
}
4548
4548
4549
+ UpdateWindowIcon ( redrawFrame : true , dpi : e . DeviceDpiNew ) ;
4549
4550
ScaleContainerForDpi ( e . DeviceDpiNew , e . DeviceDpiOld , e . SuggestedRectangle ) ;
4550
4551
}
4551
4552
finally
@@ -6417,12 +6418,17 @@ protected override void OnStyleChanged(EventArgs e)
6417
6418
/// <summary>
6418
6419
/// Updates the window icon.
6419
6420
/// </summary>
6420
- private unsafe void UpdateWindowIcon ( bool redrawFrame )
6421
+ private unsafe void UpdateWindowIcon ( bool redrawFrame , int dpi = 0 )
6421
6422
{
6422
6423
if ( IsHandleCreated )
6423
6424
{
6424
6425
Icon ? icon ;
6425
6426
6427
+ if ( dpi == 0 )
6428
+ {
6429
+ dpi = DeviceDpi ;
6430
+ }
6431
+
6426
6432
// Preserve Win32 behavior by keeping the icon we set NULL if
6427
6433
// the user hasn't specified an icon and we are a dialog frame.
6428
6434
if ( ( FormBorderStyle == FormBorderStyle . FixedDialog && _formState [ s_formStateIconSet ] == 0 ) || ! ShowIcon )
@@ -6436,20 +6442,23 @@ private unsafe void UpdateWindowIcon(bool redrawFrame)
6436
6442
6437
6443
if ( icon is not null )
6438
6444
{
6439
- if ( _smallIcon is null )
6445
+ Icon ? oldSmallIcon = _smallIcon ;
6446
+
6447
+ try
6448
+ {
6449
+ _smallIcon = ScaleHelper . ScaleSmallIconToDpi ( icon , dpi ) ;
6450
+ }
6451
+ catch
6440
6452
{
6441
- try
6442
- {
6443
- _smallIcon = new Icon ( icon , SystemInformation . SmallIconSize ) ;
6444
- }
6445
- catch
6446
- {
6447
- }
6448
6453
}
6449
6454
6450
6455
if ( _smallIcon is not null )
6451
6456
{
6452
6457
PInvokeCore . SendMessage ( this , PInvokeCore . WM_SETICON , ( WPARAM ) PInvoke . ICON_SMALL , ( LPARAM ) _smallIcon . Handle ) ;
6458
+ if ( oldSmallIcon is not null && oldSmallIcon . Handle != _smallIcon . Handle )
6459
+ {
6460
+ oldSmallIcon . Dispose ( ) ;
6461
+ }
6453
6462
}
6454
6463
6455
6464
PInvokeCore . SendMessage ( this , PInvokeCore . WM_SETICON , ( WPARAM ) PInvoke . ICON_BIG , ( LPARAM ) icon . Handle ) ;
0 commit comments