Skip to content

Commit bbafd18

Browse files
author
Mirroring
committed
Merge commit '87c7908d9c2f99317484ab202d1807bc7c49e533'
2 parents 8e5836f + 87c7908 commit bbafd18

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,14 @@ private bool WmSelChange()
19561956
if (IsAccessibilityObjectCreated && SelectedTab?.ParentInternal is TabControl)
19571957
{
19581958
SelectedTab.TabAccessibilityObject.RaiseAutomationEvent(UIA_EVENT_ID.UIA_SelectionItem_ElementSelectedEventId);
1959-
BeginInvoke((MethodInvoker)(() => SelectedTab.TabAccessibilityObject.RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId)));
1959+
BeginInvoke((MethodInvoker)(() =>
1960+
{
1961+
if (IsAccessibilityObjectCreated && SelectedTab?.ParentInternal is TabControl &&
1962+
!SelectedTab.IsDisposed && SelectedTab.TabAccessibilityObject is not null)
1963+
{
1964+
SelectedTab.TabAccessibilityObject.RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId);
1965+
}
1966+
}));
19601967
}
19611968
}
19621969
else

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControlTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5703,6 +5703,33 @@ public void TabControl_Invokes_SetToolTip_IfExternalToolTipIsSet()
57035703
Assert.Equal(text, actual);
57045704
}
57055705

5706+
[WinFormsFact]
5707+
public void TabControl_WmSelChange_SelectedTabIsNull_DoesNotThrowException()
5708+
{
5709+
using Form form = new();
5710+
using TabControl control = new();
5711+
using TabPage page1 = new("text1");
5712+
control.TabPages.Add(page1);
5713+
_ = control.AccessibilityObject;
5714+
5715+
form.Controls.Add(control);
5716+
form.Show();
5717+
control.SelectedIndex = 0;
5718+
5719+
Action act = () => control.TestAccessor().Dynamic.WmSelChange();
5720+
act.Should().NotThrow();
5721+
5722+
control.TabPages.Clear();
5723+
5724+
var exception = Record.Exception(() =>
5725+
{
5726+
Application.DoEvents();
5727+
Thread.Sleep(100);
5728+
});
5729+
5730+
exception.Should().BeNull();
5731+
}
5732+
57065733
private class SubTabPage : TabPage
57075734
{
57085735
}

0 commit comments

Comments
 (0)