Skip to content

Commit 2e819d2

Browse files
committed
Merge in 'release/8.0' changes
2 parents 6e9d49d + 2c4d171 commit 2e819d2

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ IList<Rectangle> IKeyboardToolTip.GetNeighboringToolsRectangles()
414414

415415
bool IKeyboardToolTip.IsHoveredWithMouse() => false;
416416

417-
bool IKeyboardToolTip.HasRtlModeEnabled() => DataGridView.RightToLeft == RightToLeft.Yes;
417+
bool IKeyboardToolTip.HasRtlModeEnabled() => DataGridView is not null && DataGridView.RightToLeft == RightToLeft.Yes;
418418

419419
bool IKeyboardToolTip.AllowsToolTip() => true;
420420

@@ -430,7 +430,7 @@ internal virtual void OnKeyboardToolTipUnhook(ToolTip toolTip) { }
430430

431431
string IKeyboardToolTip.GetCaptionForTool(ToolTip toolTip)
432432
{
433-
if (DataGridView.ShowCellErrors && !string.IsNullOrEmpty(ErrorText))
433+
if (DataGridView is not null && DataGridView.ShowCellErrors && !string.IsNullOrEmpty(ErrorText))
434434
{
435435
return ErrorText;
436436
}

src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,18 +1514,23 @@ internal void ShowKeyboardToolTip(string? text, IKeyboardToolTip tool, int durat
15141514
string.Format(SR.InvalidLowBoundArgumentEx, nameof(duration), (duration).ToString(CultureInfo.CurrentCulture), 0));
15151515
}
15161516

1517+
var ownerWindow = tool.GetOwnerWindow();
1518+
1519+
if (ownerWindow is null)
1520+
{
1521+
return;
1522+
}
1523+
15171524
Rectangle toolRectangle = tool.GetNativeScreenRectangle();
15181525

15191526
// At first, place the tooltip at the middle of the tool (default location).
15201527
int pointX = (toolRectangle.Left + toolRectangle.Right) / 2;
15211528
int pointY = (toolRectangle.Top + toolRectangle.Bottom) / 2;
1522-
var ownerWindow = tool.GetOwnerWindow();
1523-
Debug.Assert(ownerWindow is not null);
15241529

15251530
SetTool(ownerWindow, text, TipInfo.Type.Absolute, new Point(pointX, pointY));
15261531

15271532
// Then look for a better ToolTip location.
1528-
if (TryGetBubbleSize(tool, out Size bubbleSize))
1533+
if (TryGetBubbleSize(ownerWindow, out Size bubbleSize))
15291534
{
15301535
Point optimalPoint = GetOptimalToolTipPosition(tool, toolRectangle, bubbleSize.Width, bubbleSize.Height);
15311536

@@ -1563,7 +1568,7 @@ internal void ShowKeyboardToolTip(string? text, IKeyboardToolTip tool, int durat
15631568
}
15641569
}
15651570

1566-
private bool TryGetBubbleSize(IKeyboardToolTip tool, out Size bubbleSize)
1571+
private bool TryGetBubbleSize(IWin32Window ownerWindow, out Size bubbleSize)
15671572
{
15681573
// Get bubble size to use it for optimal position calculation. Requesting the bubble
15691574
// size will AV if there isn't a current tool window.
@@ -1573,7 +1578,7 @@ private bool TryGetBubbleSize(IKeyboardToolTip tool, out Size bubbleSize)
15731578

15741579
if (!hwnd.IsNull)
15751580
{
1576-
ToolInfoWrapper<HandleRef<HWND>> info = new(Control.GetSafeHandle(tool.GetOwnerWindow()!));
1581+
ToolInfoWrapper<HandleRef<HWND>> info = new(Control.GetSafeHandle(ownerWindow));
15771582
result = info.SendMessage(this, PInvoke.TTM_GETBUBBLESIZE);
15781583
}
15791584

0 commit comments

Comments
 (0)