Skip to content

Commit 0a7e319

Browse files
committed
Improved the DPI awareness (display scaling) in the TreeViewAdv control.
1 parent ad58051 commit 0a7e319

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

External/Aga.Controls/Tree/TreeViewAdv.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

External/Aga.Controls/Tree/TreeViewAdv.Draw.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ private void CreatePens()
4141
{
4242
CreateLinePen();
4343
CreateMarkPen();
44-
}
44+
CreateLightGrayPen();
45+
}
4546

4647
private void CreateMarkPen()
4748
{
@@ -59,7 +60,14 @@ private void CreateLinePen()
5960
{
6061
_linePen = new Pen(_lineColor);
6162
_linePen.DashStyle = DashStyle.Dot;
62-
}
63+
_linePen.Width = GetScaledSize(1, false);
64+
}
65+
66+
private void CreateLightGrayPen()
67+
{
68+
_lightGrayPen = new Pen(Color.FromArgb(247, 247, 247));
69+
_lightGrayPen.Width = GetScaledSize(1, false);
70+
}
6371

6472
protected override void OnPaint(PaintEventArgs e)
6573
{
@@ -136,7 +144,7 @@ private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectang
136144
OnRowDraw(e, node, context, row, rowRect);
137145

138146
if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal) {
139-
e.Graphics.DrawLine(LightGrayPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
147+
e.Graphics.DrawLine(_lightGrayPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
140148
}
141149

142150
if (FullRowSelect)
@@ -164,8 +172,7 @@ private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectang
164172
DrawNode(node, context);
165173
}
166174

167-
private Brush GrayBrush = new SolidBrush(Color.FromArgb(240, 240, 240));
168-
private Pen LightGrayPen = new Pen(Color.FromArgb(247, 247, 247));
175+
private Brush GrayBrush = new SolidBrush(Color.FromArgb(240, 240, 240));
169176

170177
private void DrawVerticalGridLines(Graphics gr, int y)
171178
{
@@ -260,7 +267,8 @@ private void DrawLines(Graphics gr, TreeNodeAdv node, Rectangle rowRect)
260267
{
261268
int level = curNode.Level;
262269
int scaledIndent = node.Tree.GetScaledSize(_indent, false);
263-
int x = (level - 1) * scaledIndent + NodePlusMinus.ImageSize / 2 + LeftMargin;
270+
int x = (level - 1) * scaledIndent +
271+
node.Tree.GetScaledSize(NodePlusMinus.ImageSize, false) / 2 + LeftMargin;
264272
int width = node.Tree.GetScaledSize(NodePlusMinus.Width - NodePlusMinus.ImageSize / 2, false);
265273
int y = rowRect.Y;
266274
int y2 = y + rowRect.Height;

External/Aga.Controls/Tree/TreeViewAdv.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public partial class TreeViewAdv : Control
3030
private const int DividerCorrectionGap = -2;
3131

3232
private Pen _linePen;
33+
private Pen _lightGrayPen;
3334
private Pen _markPen;
3435
private bool _suspendUpdate;
3536
private bool _needFullUpdate;
@@ -256,7 +257,7 @@ public void SetDPI()
256257
{
257258
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx
258259
const int _default_dpi = 96;
259-
Graphics g = this.CreateGraphics();
260+
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
260261

261262
try
262263
{

0 commit comments

Comments
 (0)