@@ -1514,18 +1514,23 @@ internal void ShowKeyboardToolTip(string? text, IKeyboardToolTip tool, int durat
1514
1514
string . Format ( SR . InvalidLowBoundArgumentEx , nameof ( duration ) , ( duration ) . ToString ( CultureInfo . CurrentCulture ) , 0 ) ) ;
1515
1515
}
1516
1516
1517
+ var ownerWindow = tool . GetOwnerWindow ( ) ;
1518
+
1519
+ if ( ownerWindow is null )
1520
+ {
1521
+ return ;
1522
+ }
1523
+
1517
1524
Rectangle toolRectangle = tool . GetNativeScreenRectangle ( ) ;
1518
1525
1519
1526
// At first, place the tooltip at the middle of the tool (default location).
1520
1527
int pointX = ( toolRectangle . Left + toolRectangle . Right ) / 2 ;
1521
1528
int pointY = ( toolRectangle . Top + toolRectangle . Bottom ) / 2 ;
1522
- var ownerWindow = tool . GetOwnerWindow ( ) ;
1523
- Debug . Assert ( ownerWindow is not null ) ;
1524
1529
1525
1530
SetTool ( ownerWindow , text , TipInfo . Type . Absolute , new Point ( pointX , pointY ) ) ;
1526
1531
1527
1532
// Then look for a better ToolTip location.
1528
- if ( TryGetBubbleSize ( tool , out Size bubbleSize ) )
1533
+ if ( TryGetBubbleSize ( ownerWindow , out Size bubbleSize ) )
1529
1534
{
1530
1535
Point optimalPoint = GetOptimalToolTipPosition ( tool , toolRectangle , bubbleSize . Width , bubbleSize . Height ) ;
1531
1536
@@ -1563,7 +1568,7 @@ internal void ShowKeyboardToolTip(string? text, IKeyboardToolTip tool, int durat
1563
1568
}
1564
1569
}
1565
1570
1566
- private bool TryGetBubbleSize ( IKeyboardToolTip tool , out Size bubbleSize )
1571
+ private bool TryGetBubbleSize ( IWin32Window ownerWindow , out Size bubbleSize )
1567
1572
{
1568
1573
// Get bubble size to use it for optimal position calculation. Requesting the bubble
1569
1574
// size will AV if there isn't a current tool window.
@@ -1573,7 +1578,7 @@ private bool TryGetBubbleSize(IKeyboardToolTip tool, out Size bubbleSize)
1573
1578
1574
1579
if ( ! hwnd . IsNull )
1575
1580
{
1576
- ToolInfoWrapper < HandleRef < HWND > > info = new ( Control . GetSafeHandle ( tool . GetOwnerWindow ( ) ! ) ) ;
1581
+ ToolInfoWrapper < HandleRef < HWND > > info = new ( Control . GetSafeHandle ( ownerWindow ) ) ;
1577
1582
result = info . SendMessage ( this , PInvoke . TTM_GETBUBBLESIZE ) ;
1578
1583
}
1579
1584
0 commit comments