Skip to content

Commit

Permalink
Fix ControlPaint.DrawBorder rendering (#3952)
Browse files Browse the repository at this point in the history
Fixes #3945

The DrawBorder overload that takes individual side parameters needed to adjust line ends when drawing in GDI.

Manually validated output at different widths and transparencies between 3.1 and 5.0. Will follow up with automated regression tests in a separate PR.
  • Loading branch information
JeremyKuhne committed Sep 19, 2020
1 parent 4649753 commit d8fd73b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ public static void DrawBorder(Graphics graphics, Rectangle bounds, Color color,
using var hpen = new Gdi32.CreatePenScope(topColor);
for (int i = 0; i < topWidth; i++)
{
hdc.DrawLine(hpen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);
// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(hpen, topLineLefts[i], bounds.Y + i, topLineRights[i] + 1, bounds.Y + i);
}
}
else
Expand Down Expand Up @@ -778,7 +779,9 @@ topStyle switch
using var hpen = new Gdi32.CreatePenScope(topStyle == ButtonBorderStyle.Inset
? hlsColor.Darker(1.0f - i * inc)
: hlsColor.Lighter(1.0f - i * inc));
hdc.DrawLine(hpen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);

// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(hpen, topLineLefts[i], bounds.Y + i, topLineRights[i] + 1, bounds.Y + i);
}
break;
}
Expand All @@ -799,7 +802,8 @@ topStyle switch
using var hpen = new Gdi32.CreatePenScope(leftColor);
for (int i = 0; i < leftWidth; i++)
{
hdc.DrawLine(hpen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);
// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(hpen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i] + 1);
}
}
else
Expand Down Expand Up @@ -831,7 +835,9 @@ leftStyle switch
using var hpen = new Gdi32.CreatePenScope(leftStyle == ButtonBorderStyle.Inset
? hlsColor.Darker(1.0f - i * inc)
: hlsColor.Lighter(1.0f - i * inc));
hdc.DrawLine(hpen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);

// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(hpen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i] + 1);
}
break;
}
Expand All @@ -852,11 +858,12 @@ leftStyle switch
using var hpen = new Gdi32.CreatePenScope(bottomColor);
for (int i = 0; i < bottomWidth; i++)
{
// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(
hpen,
bottomLineLefts[i],
bounds.Y + bounds.Height - 1 - i,
bottomLineRights[i],
bottomLineRights[i] + 1,
bounds.Y + bounds.Height - 1 - i);
}
}
Expand Down Expand Up @@ -894,11 +901,13 @@ bottomStyle switch
using var hpen = new Gdi32.CreatePenScope(bottomStyle != ButtonBorderStyle.Inset
? hlsColor.Darker(1.0f - i * inc)
: hlsColor.Lighter(1.0f - i * inc));

// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(
hpen,
bottomLineLefts[i],
bounds.Y + bounds.Height - 1 - i,
bottomLineRights[i],
bottomLineRights[i] + 1,
bounds.Y + bounds.Height - 1 - i);
}
break;
Expand All @@ -920,12 +929,13 @@ bottomStyle switch
using var hpen = new Gdi32.CreatePenScope(rightColor);
for (int i = 0; i < rightWidth; i++)
{
// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(
hpen,
bounds.X + bounds.Width - 1 - i,
rightLineTops[i],
bounds.X + bounds.Width - 1 - i,
rightLineBottoms[i]);
rightLineBottoms[i] + 1);
}
}
else
Expand Down Expand Up @@ -963,11 +973,12 @@ rightStyle switch
? hlsColor.Darker(1.0f - i * inc)
: hlsColor.Lighter(1.0f - i * inc));

// Need to add one to the destination point for GDI to render the same as GDI+
hdc.DrawLine(hpen,
bounds.X + bounds.Width - 1 - i,
rightLineTops[i],
bounds.X + bounds.Width - 1 - i,
rightLineBottoms[i]);
rightLineBottoms[i] + 1);
}
break;
}
Expand Down

0 comments on commit d8fd73b

Please sign in to comment.