diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs index 56992511bdb..1823946b07b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs @@ -75,6 +75,11 @@ public virtual void DrawPopUpCombo(ComboBox comboBox, Graphics g) { DrawFlatCombo(comboBox, g); } + else + { + // Draw the drop down + DrawFlatComboDropDown(comboBox, g, _dropDownRect); + } bool rightToLeft = comboBox.RightToLeft == RightToLeft.Yes; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs index 2ba076ddf47..25227b0bde6 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs @@ -3764,7 +3764,10 @@ protected override unsafe void WndProc(ref Message m) } using Graphics g = Graphics.FromHdcInternal((IntPtr)dc); - if ((!Enabled || FlatStyle == FlatStyle.Popup) && MouseIsOver) + + // The pop up border needs to be drawn only when the control gets the focus or the mouse hovers over it. + bool isPopupAndActive = FlatStyle == FlatStyle.Popup && (Focused || MouseIsOver); + if (!Enabled || isPopupAndActive) { FlatComboBoxAdapter.DrawPopUpCombo(this, g); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs index fbf943b8265..2670358a26d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs @@ -2750,6 +2750,38 @@ private void InitializeItems(ComboBox comboBox, int numItems) Assert.Equal(numItems, comboBox.Items.Count); } + [WinFormsFact] + public void ComboBox_OnLostFocus_AutoCompleteModeNone_DoesNotClearMatchingText() + { + using ComboBox comboBox = new(); + var comboBoxAccessor = comboBox.TestAccessor().Dynamic; + comboBoxAccessor._canFireLostFocus= true; + comboBox.AutoCompleteMode = AutoCompleteMode.None; + comboBox.AutoCompleteSource = AutoCompleteSource.ListItems; + comboBoxAccessor.MatchingText = "Test"; + comboBox.DropDownStyle = ComboBoxStyle.Simple; + comboBoxAccessor.OnLostFocus(EventArgs.Empty); + + string matchingText = comboBoxAccessor.MatchingText; + matchingText.Should().Be("Test"); + } + + [WinFormsFact] + public void ComboBox_OnLostFocus_AutoCompleteModeNotNone_ClearsMatchingText() + { + using ComboBox comboBox = new(); + var comboBoxAccessor = comboBox.TestAccessor().Dynamic; + comboBoxAccessor._canFireLostFocus = true; + comboBox.AutoCompleteMode = AutoCompleteMode.Suggest; + comboBox.AutoCompleteSource = AutoCompleteSource.ListItems; + comboBox.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxAccessor.MatchingText = "Test"; + comboBoxAccessor.OnLostFocus(EventArgs.Empty); + + string matchingText = comboBoxAccessor.MatchingText; + matchingText.Should().BeEmpty(); + } + private class OwnerDrawComboBox : ComboBox { public OwnerDrawComboBox()