Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset MouseIsOver when the control loses focus #12598

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
LeafShi1 marked this conversation as resolved.
Show resolved Hide resolved
if (!Enabled || isPopupAndActive)
{
FlatComboBoxAdapter.DrawPopUpCombo(this, g);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,38 @@ private void InitializeItems(ComboBox comboBox, int numItems)
Assert.Equal(numItems, comboBox.Items.Count);
}

[WinFormsFact]
public void ComboBox_OnLostFocus_AutoCompleteModeNone_DoesNotClearMatchingText()
LeafShi1 marked this conversation as resolved.
Show resolved Hide resolved
{
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()
Expand Down
Loading