File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
src/System/Windows/Forms/Controls/TabControl
tests/UnitTests/System/Windows/Forms Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -1956,7 +1956,14 @@ private bool WmSelChange()
1956
1956
if ( IsAccessibilityObjectCreated && SelectedTab ? . ParentInternal is TabControl )
1957
1957
{
1958
1958
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
+ } ) ) ;
1960
1967
}
1961
1968
}
1962
1969
else
Original file line number Diff line number Diff line change @@ -5703,6 +5703,33 @@ public void TabControl_Invokes_SetToolTip_IfExternalToolTipIsSet()
5703
5703
Assert . Equal ( text , actual ) ;
5704
5704
}
5705
5705
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
+
5706
5733
private class SubTabPage : TabPage
5707
5734
{
5708
5735
}
You can’t perform that action at this time.
0 commit comments