Skip to content

Commit

Permalink
Fix FlatStyle drawing of ComboBox (#6505)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhensley authored Jan 18, 2022
1 parent 358f9a3 commit 40dd779
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using System.Drawing;
using System.Windows.Forms.Layout;
using static Interop;
using static Interop.User32;

namespace System.Windows.Forms
{
Expand Down Expand Up @@ -185,48 +183,6 @@ protected virtual Color GetPopupOuterBorderColor(ComboBox comboBox, bool focused

protected virtual Color GetInnerBorderColor(ComboBox comboBox)
=> comboBox.Enabled ? comboBox.BackColor : SystemColors.Control;

/// <summary>
/// This eliminates flicker by removing the pieces we're going to paint ourselves from the update region.
/// Note the UpdateRegionBox is the bounding box of the actual update region. This is here so we can
/// quickly eliminate rectangles that aren't in the update region.
/// </summary>
public unsafe void ValidateOwnerDrawRegions(ComboBox comboBox, Rectangle updateRegionBox)
{
if (comboBox is null)
{
return;
}

Rectangle topOwnerDrawArea = new Rectangle(0, 0, comboBox.Width, _innerBorder.Top);
Rectangle bottomOwnerDrawArea = new Rectangle(0, _innerBorder.Bottom, comboBox.Width, comboBox.Height - _innerBorder.Bottom);
Rectangle leftOwnerDrawArea = new Rectangle(0, 0, _innerBorder.Left, comboBox.Height);
Rectangle rightOwnerDrawArea = new Rectangle(_innerBorder.Right, 0, comboBox.Width - _innerBorder.Right, comboBox.Height);

if (topOwnerDrawArea.IntersectsWith(updateRegionBox))
{
RECT validRect = new RECT(topOwnerDrawArea);
ValidateRect(comboBox, &validRect);
}

if (bottomOwnerDrawArea.IntersectsWith(updateRegionBox))
{
RECT validRect = new RECT(bottomOwnerDrawArea);
ValidateRect(comboBox, &validRect);
}

if (leftOwnerDrawArea.IntersectsWith(updateRegionBox))
{
RECT validRect = new RECT(leftOwnerDrawArea);
ValidateRect(comboBox, &validRect);
}

if (rightOwnerDrawArea.IntersectsWith(updateRegionBox))
{
RECT validRect = new RECT(rightOwnerDrawArea);
ValidateRect(comboBox, &validRect);
}
}
}
}
}
2 changes: 0 additions & 2 deletions src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3915,8 +3915,6 @@ protected override void WndProc(ref Message m)
RECT updateRegionBoundingRect = default;
Gdi32.GetRgnBox(windowRegion, ref updateRegionBoundingRect);

FlatComboBoxAdapter.ValidateOwnerDrawRegions(this, updateRegionBoundingRect);

// Call the base class to do its painting (with a clipped DC).
bool useBeginPaint = m.WParamInternal == 0;
using var paintScope = useBeginPaint ? new BeginPaintScope(Handle) : default;
Expand Down

0 comments on commit 40dd779

Please sign in to comment.