Skip to content
Merged
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 @@ -60,6 +60,43 @@ public bool IsValid(ComboBox combo)
return (combo.ClientRectangle == _clientRect && combo.RightToLeft == _origRightToLeft);
}

public virtual void DrawPopUpCombo(ComboBox comboBox, Graphics g)
{
if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
{
return;
}

bool rightToLeft = comboBox.RightToLeft == RightToLeft.Yes;

// Draw a dark border around everything if we're in popup mode
if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
{
bool focused = comboBox.ContainsFocus || comboBox.MouseIsOver;
Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);

using var borderPen = borderPenColor.GetCachedPenScope();
Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;

// Draw a border around the dropdown.
if (rightToLeft)
{
g.DrawRectangle(
innerPen,
new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
}
else
{
g.DrawRectangle(
innerPen,
new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
}

// Draw a border around the whole comboBox.
g.DrawRectangle(borderPen, _outerBorder);
}
}

/// <summary>
/// Paints over the edges of the combo box to make it appear flat.
/// </summary>
Expand Down Expand Up @@ -107,33 +144,6 @@ public virtual void DrawFlatCombo(ComboBox comboBox, Graphics g)
using var innerBorderPen = innerBorderColor.GetCachedPenScope();
g.DrawRectangle(innerBorderPen, _innerBorder);
g.DrawRectangle(innerBorderPen, _innerInnerBorder);

// Draw a dark border around everything if we're in popup mode
if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
{
bool focused = comboBox.ContainsFocus || comboBox.MouseIsOver;
Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);

using var borderPen = borderPenColor.GetCachedPenScope();
Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;

// Around the dropdown
if (rightToLeft)
{
g.DrawRectangle(
innerPen,
new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
}
else
{
g.DrawRectangle(
innerPen,
new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
}

// Around the whole combobox.
g.DrawRectangle(borderPen, _outerBorder);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3885,7 +3885,14 @@ protected override unsafe void WndProc(ref Message m)
}

using Graphics g = Graphics.FromHdcInternal((IntPtr)dc);
FlatComboBoxAdapter.DrawFlatCombo(this, g);
if ((!Enabled || FlatStyle == FlatStyle.Popup) && MouseIsOver)
{
FlatComboBoxAdapter.DrawPopUpCombo(this, g);
}
else
{
FlatComboBoxAdapter.DrawFlatCombo(this, g);
}

return;
}
Expand Down