From ba981cd8acb48acf34354c2da4e71ae76661586b Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 19 Dec 2024 21:56:03 +0800 Subject: [PATCH] feat: fix date range start selection when tab into the control. --- .../DateTimePicker/DateRangePicker.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs b/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs index 157a2f4..775d66b 100644 --- a/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs +++ b/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs @@ -457,5 +457,32 @@ public class DateRangePicker : DatePickerBase, IClearControl break; } } - + + protected override void OnGotFocus(GotFocusEventArgs e) + { + base.OnGotFocus(e); + FocusChanged(IsKeyboardFocusWithin); + } + + private bool _isFocused; + private void FocusChanged(bool hasFocus) + { + // The OnGotFocus & OnLostFocus are asynchronously and cannot + // reliably tell you that have the focus. All they do is let you + // know that the focus changed sometime in the past. To determine + // if you currently have the focus you need to do consult the + // FocusManager. + + bool wasFocused = _isFocused; + _isFocused = hasFocus; + + if (hasFocus) + { + + if (!wasFocused && _start == null) + { + _start = true; + } + } + } } \ No newline at end of file