diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/MonthCalendar/MonthCalendar.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/MonthCalendar/MonthCalendar.cs index 84f0f5ca331..615a981ad36 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/MonthCalendar/MonthCalendar.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/MonthCalendar/MonthCalendar.cs @@ -1428,6 +1428,8 @@ protected override void OnGotFocus(EventArgs e) { base.OnGotFocus(e); + NotifyWinEvent(AccessibleEvents.Focus); + if (IsAccessibilityObjectCreated) { ((MonthCalendarAccessibleObject)AccessibilityObject).FocusedCell?.RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId); @@ -2063,8 +2065,9 @@ private unsafe void WmDateChanged(ref Message m) _selectionStart = start; _selectionEnd = end; - AccessibilityNotifyClients(AccessibleEvents.NameChange, -1); - AccessibilityNotifyClients(AccessibleEvents.ValueChange, -1); + NotifyWinEvent(AccessibleEvents.Focus); + NotifyWinEvent(AccessibleEvents.NameChange); + NotifyWinEvent(AccessibleEvents.ValueChange); // We should use the Date for comparison in this case. The user can work in the calendar only with dates, // while the minimum / maximum date can contain the date and custom time, which, when comparing Ticks, @@ -2094,6 +2097,25 @@ private unsafe void WmDateChanged(ref Message m) OnDateChanged(new DateRangeEventArgs(start, end)); } + private void NotifyWinEvent(AccessibleEvents accessibleEvent) + { + try + { + if (IsHandleCreated) + { + PInvoke.NotifyWinEvent( + (uint)accessibleEvent, + this, + (int)OBJECT_IDENTIFIER.OBJID_CLIENT, + (int)PInvoke.CHILDID_SELF); + } + } + catch (Exception ex) + { + Debug.Fail($"NotifyWinEvent failed: {ex.Message}"); + } + } + /// /// Handles the MCN_GETDAYSTATE notification by returning an array of bitmasks, one entry per month, /// that specifies which dates to display in bold.