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

Closed
Show file tree
Hide file tree
Changes from 3 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 @@ -2747,6 +2747,12 @@ protected override void OnLostFocus(EventArgs e)

base.OnLostFocus(e);
_canFireLostFocus = false;

// When the control loses focus, reset the MouseIsOver to False.
if (DropDownStyle == ComboBoxStyle.Simple || !DroppedDown)
{
MouseIsOver = false;
}
}
}

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();
comboBox.TestAccessor().Dynamic._canFireLostFocus= true;
LeafShi1 marked this conversation as resolved.
Show resolved Hide resolved
comboBox.AutoCompleteMode = AutoCompleteMode.None;
comboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox.TestAccessor().Dynamic.MatchingText = "Test";
comboBox.DropDownStyle = ComboBoxStyle.Simple;
comboBox.TestAccessor().Dynamic.OnLostFocus(EventArgs.Empty);

string matchingText = comboBox.TestAccessor().Dynamic.MatchingText;
matchingText.Should().Be("Test");
comboBox.MouseIsOver.Should().BeFalse();
}

[WinFormsFact]
public void ComboBox_OnLostFocus_AutoCompleteModeNotNone_ClearsMatchingText()
{
using ComboBox comboBox = new();
comboBox.TestAccessor().Dynamic._canFireLostFocus = true;
comboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox.TestAccessor().Dynamic.MatchingText = "Test";
comboBox.TestAccessor().Dynamic.OnLostFocus(EventArgs.Empty);

string matchingText = comboBox.TestAccessor().Dynamic.MatchingText;
matchingText.Should().BeEmpty();
comboBox.MouseIsOver.Should().BeFalse();
}

private class OwnerDrawComboBox : ComboBox
{
public OwnerDrawComboBox()
Expand Down