Improved the DPI awareness (display scaling) in the TreeViewAdv control.

This commit is contained in:
Michael Möller
2020-05-24 23:09:59 +02:00
parent ad58051a92
commit 0a7e319356
3 changed files with 17 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ namespace Aga.Controls.Tree
if (_dragTimer != null) _dragTimer.Dispose();
if (_linePen != null) _linePen.Dispose();
if (_markPen != null) _markPen.Dispose();
if (_lightGrayPen != null) _lightGrayPen.Dispose();
}
base.Dispose(disposing);
}

View File

@@ -41,7 +41,8 @@ namespace Aga.Controls.Tree
{
CreateLinePen();
CreateMarkPen();
}
CreateLightGrayPen();
}
private void CreateMarkPen()
{
@@ -59,7 +60,14 @@ namespace Aga.Controls.Tree
{
_linePen = new Pen(_lineColor);
_linePen.DashStyle = DashStyle.Dot;
}
_linePen.Width = GetScaledSize(1, false);
}
private void CreateLightGrayPen()
{
_lightGrayPen = new Pen(Color.FromArgb(247, 247, 247));
_lightGrayPen.Width = GetScaledSize(1, false);
}
protected override void OnPaint(PaintEventArgs e)
{
@@ -136,7 +144,7 @@ namespace Aga.Controls.Tree
OnRowDraw(e, node, context, row, rowRect);
if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal) {
e.Graphics.DrawLine(LightGrayPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
e.Graphics.DrawLine(_lightGrayPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
}
if (FullRowSelect)
@@ -164,8 +172,7 @@ namespace Aga.Controls.Tree
DrawNode(node, context);
}
private Brush GrayBrush = new SolidBrush(Color.FromArgb(240, 240, 240));
private Pen LightGrayPen = new Pen(Color.FromArgb(247, 247, 247));
private Brush GrayBrush = new SolidBrush(Color.FromArgb(240, 240, 240));
private void DrawVerticalGridLines(Graphics gr, int y)
{
@@ -260,7 +267,8 @@ namespace Aga.Controls.Tree
{
int level = curNode.Level;
int scaledIndent = node.Tree.GetScaledSize(_indent, false);
int x = (level - 1) * scaledIndent + NodePlusMinus.ImageSize / 2 + LeftMargin;
int x = (level - 1) * scaledIndent +
node.Tree.GetScaledSize(NodePlusMinus.ImageSize, false) / 2 + LeftMargin;
int width = node.Tree.GetScaledSize(NodePlusMinus.Width - NodePlusMinus.ImageSize / 2, false);
int y = rowRect.Y;
int y2 = y + rowRect.Height;

View File

@@ -30,6 +30,7 @@ namespace Aga.Controls.Tree
private const int DividerCorrectionGap = -2;
private Pen _linePen;
private Pen _lightGrayPen;
private Pen _markPen;
private bool _suspendUpdate;
private bool _needFullUpdate;
@@ -256,7 +257,7 @@ namespace Aga.Controls.Tree
{
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx
const int _default_dpi = 96;
Graphics g = this.CreateGraphics();
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
try
{