@@ -42,6 +42,11 @@ public partial class TreeViewAdv : Control
4242 private List < TreeNodeAdv > _expandingNodes = new List < TreeNodeAdv > ( ) ;
4343 private AbortableThreadPool _threadPool = new AbortableThreadPool ( ) ;
4444
45+ private float dpiX ;
46+ private float dpiY ;
47+ private float dpiXscale = 1 ;
48+ private float dpiYscale = 1 ;
49+
4550 #region Public Events
4651
4752 [ Category ( "Action" ) ]
@@ -204,6 +209,7 @@ protected virtual void OnDropNodeValidating(Point point, ref TreeNodeAdv node)
204209 public TreeViewAdv ( )
205210 {
206211 InitializeComponent ( ) ;
212+ SetDPI ( ) ;
207213 SetStyle ( ControlStyles . AllPaintingInWmPaint
208214 | ControlStyles . UserPaint
209215 | ControlStyles . OptimizedDoubleBuffer
@@ -216,6 +222,7 @@ public TreeViewAdv()
216222 _columnHeaderHeight = 20 ;
217223 else
218224 _columnHeaderHeight = 17 ;
225+ _columnHeaderHeight = GetScaledSize ( _columnHeaderHeight ) ;
219226
220227 //BorderStyle = BorderStyle.Fixed3D;
221228 _hScrollBar . Height = SystemInformation . HorizontalScrollBarHeight ;
@@ -245,6 +252,46 @@ public TreeViewAdv()
245252 ExpandingIcon . IconChanged += ExpandingIconChanged ;
246253 }
247254
255+ public void SetDPI ( )
256+ {
257+ // https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx
258+ const int _default_dpi = 96 ;
259+ Graphics g = this . CreateGraphics ( ) ;
260+
261+ try
262+ {
263+ this . dpiX = g . DpiX ;
264+ this . dpiY = g . DpiY ;
265+ }
266+ finally
267+ {
268+ g . Dispose ( ) ;
269+ }
270+ if ( dpiX > 0 )
271+ {
272+ this . dpiXscale = dpiX / _default_dpi ;
273+ }
274+ if ( dpiY > 0 )
275+ {
276+ this . dpiYscale = dpiY / _default_dpi ;
277+ }
278+ }
279+
280+ public int GetScaledSize ( int size , bool useY = true )
281+ {
282+ int scaledsize = size ;
283+
284+ if ( useY && this . dpiYscale > 1 )
285+ {
286+ scaledsize = ( int ) ( this . dpiYscale * size ) ;
287+ }
288+ else if ( this . dpiXscale > 1 )
289+ {
290+ scaledsize = ( int ) ( this . dpiXscale * size ) ;
291+ }
292+ return scaledsize ;
293+ }
294+
248295 void ExpandingIconChanged ( object sender , EventArgs e )
249296 {
250297 if ( IsHandleCreated && ! IsDisposed )
@@ -543,11 +590,12 @@ internal IEnumerable<NodeControlInfo> GetNodeControls(TreeNodeAdv node, Rectangl
543590 if ( node == null )
544591 yield break ;
545592
593+ int scaledIndent = node . Tree . GetScaledSize ( _indent , false ) ;
546594 int y = rowRect . Y ;
547- int x = ( node . Level - 1 ) * _indent + LeftMargin ;
595+ int x = ( node . Level - 1 ) * scaledIndent + LeftMargin ;
548596 int width = 0 ;
549597 if ( node . Row == 0 && ShiftFirstNode )
550- x -= _indent ;
598+ x -= scaledIndent ;
551599 Rectangle rect = Rectangle . Empty ;
552600
553601 if ( ShowPlusMinus )
0 commit comments