@@ -19,10 +19,10 @@ public class TreeView : Control
19
19
private bool _scrollVisible = false ; // smooth scrolling.
20
20
private bool _scroll ;
21
21
private bool _scrollHovered ;
22
- private float _scrollIndex ;
23
- private float _scrollY ;
24
- private float _scrollHeight ;
25
- private float _scrollWidth = 10 ;
22
+ protected float scrollIndex ;
23
+ private float _scrollbarY ;
24
+ private float _scrollbarHeight ;
25
+ private float _scrollbarWidth = 10 ;
26
26
private float _scrollStartY ;
27
27
private float _scroll_ItemsEstimatedHeigh ;
28
28
private List < TreeNode > _scrollNodeList ;
@@ -35,7 +35,7 @@ public class TreeView : Control
35
35
public ImageList ImageList { get { return _imageList ; } set { _imageList = value ; } }
36
36
public int ItemHeight { get ; set ; }
37
37
public TreeNodeCollection Nodes { get { return _nodes ; } private set { _nodes = value ; } }
38
- public float ScrollIndex { get { return _scrollIndex ; } internal set { _scrollIndex = value ; } }
38
+ public float ScrollIndex { get { return scrollIndex ; } internal set { scrollIndex = value ; } }
39
39
public float ScrollSpeed { get ; set ; }
40
40
public TreeNode SelectedNode { get ; set ; }
41
41
public Color SelectionColor { get ; set ; }
@@ -70,15 +70,15 @@ private void _AddjustScrollIndexToSelectedNode()
70
70
{
71
71
if ( SelectedNode != null )
72
72
{
73
- if ( _scrollIndex > SelectedNode . Bounds . Y )
73
+ if ( scrollIndex > SelectedNode . Bounds . Y )
74
74
{
75
75
76
- _scrollIndex = SelectedNode . Bounds . Y ;
76
+ scrollIndex = SelectedNode . Bounds . Y ;
77
77
_UpdateScrollList ( ) ;
78
78
}
79
- if ( _scrollIndex + Height < SelectedNode . Bounds . Y + ItemHeight )
79
+ if ( scrollIndex + Height < SelectedNode . Bounds . Y + ItemHeight )
80
80
{
81
- _scrollIndex = SelectedNode . Bounds . Y + ItemHeight - Height ;
81
+ scrollIndex = SelectedNode . Bounds . Y + ItemHeight - Height ;
82
82
_UpdateScrollList ( ) ;
83
83
}
84
84
}
@@ -95,22 +95,22 @@ private void _FixScrollIndex()
95
95
{
96
96
if ( _nodeList == null || _nodeList . Count == 0 )
97
97
{
98
- _scrollIndex = 0 ;
98
+ scrollIndex = 0 ;
99
99
return ;
100
100
}
101
101
102
102
if ( SmoothScrolling == false )
103
- _scrollIndex = ( float ) Math . Ceiling ( _scrollIndex / ItemHeight ) * ItemHeight ;
103
+ scrollIndex = ( float ) Math . Ceiling ( scrollIndex / ItemHeight ) * ItemHeight ;
104
104
105
- if ( _scrollIndex > _nodeList . Last ( ) . Bounds . Y + ItemHeight - Height ) _scrollIndex = _nodeList . Last ( ) . Bounds . Y + ItemHeight - Height ;
106
- if ( _scrollIndex < 0 ) _scrollIndex = 0 ;
105
+ if ( scrollIndex > _nodeList . Last ( ) . Bounds . Y + ItemHeight - Height ) scrollIndex = _nodeList . Last ( ) . Bounds . Y + ItemHeight - Height ;
106
+ if ( scrollIndex < 0 ) scrollIndex = 0 ;
107
107
}
108
108
private TreeNode _GetNodeAtPosition ( TreeNode rootNode , Point position )
109
109
{
110
110
if ( rootNode != root && rootNode . IsVisible )
111
111
{
112
112
int nodeWidth = Width ;
113
- var rootNodeRect = new Rectangle ( rootNode . Bounds . X , rootNode . Bounds . Y - ( int ) _scrollIndex , nodeWidth , rootNode . Bounds . Height ) ;
113
+ var rootNodeRect = new Rectangle ( rootNode . Bounds . X , rootNode . Bounds . Y - ( int ) scrollIndex , nodeWidth , rootNode . Bounds . Height ) ;
114
114
if ( UseNodeBoundsForSelection == false ) rootNodeRect . X = 0 ;
115
115
if ( rootNodeRect . Contains ( position ) )
116
116
return rootNode ;
@@ -143,7 +143,7 @@ private void _OnDrawNode(object sender, DrawTreeNodeEventArgs e)
143
143
{
144
144
// Node drawing.
145
145
e . Graphics . FillRectangle ( new SolidBrush ( e . Node . BackColor ) , e . Node . Bounds ) ;
146
- if ( e . Node . IsSelected ) e . Graphics . FillRectangle ( new SolidBrush ( SelectionColor ) , UseNodeBoundsForSelection ? e . Node . Bounds . X : 0 , e . Node . Bounds . Y - ( int ) _scrollIndex , Width , ItemHeight ) ;
146
+ if ( e . Node . IsSelected ) e . Graphics . FillRectangle ( new SolidBrush ( SelectionColor ) , UseNodeBoundsForSelection ? e . Node . Bounds . X : 0 , e . Node . Bounds . Y - ( int ) scrollIndex , Width , ItemHeight ) ;
147
147
148
148
bool hasImage = false ;
149
149
int imageWidth = 0 ;
@@ -152,15 +152,15 @@ private void _OnDrawNode(object sender, DrawTreeNodeEventArgs e)
152
152
var image = ImageList . Images [ e . Node . ImageIndex ] ;
153
153
if ( image != null && image . uTexture != null )
154
154
{
155
- e . Graphics . DrawTexture ( image . uTexture , e . Node . Bounds . X , e . Node . Bounds . Y + e . Node . Bounds . Height / 2 - image . Height / 2 - ( int ) _scrollIndex , image . Width , image . Height , e . Node . ImageColor ) ;
155
+ e . Graphics . DrawTexture ( image . uTexture , e . Node . Bounds . X , e . Node . Bounds . Y + e . Node . Bounds . Height / 2 - image . Height / 2 - ( int ) scrollIndex , image . Width , image . Height , e . Node . ImageColor ) ;
156
156
hasImage = true ;
157
157
imageWidth = image . Width ;
158
158
}
159
159
}
160
160
161
161
string stringToDraw = e . Node . Text ;
162
162
if ( stringToDraw == null && e . Node . Tag != null ) stringToDraw = e . Node . Tag . ToString ( ) ;
163
- e . Graphics . DrawString ( stringToDraw , Font , new SolidBrush ( e . Node . ForeColor ) , e . Node . Bounds . X + ( hasImage ? imageWidth + 2 : 0 ) , e . Node . Bounds . Y - ( int ) _scrollIndex - 2 , ( WrapText ? Width : Width * 16 ) , e . Bounds . Height + 4 , ContentAlignment . MiddleLeft ) ;
163
+ e . Graphics . DrawString ( stringToDraw , Font , new SolidBrush ( e . Node . ForeColor ) , e . Node . Bounds . X + ( hasImage ? imageWidth + 2 : 0 ) , e . Node . Bounds . Y - ( int ) scrollIndex - 2 , ( WrapText ? Width : Width * 16 ) , e . Bounds . Height + 4 , ContentAlignment . MiddleLeft ) ;
164
164
// End of drawing.
165
165
166
166
DrawNode ( this , e ) ;
@@ -228,13 +228,13 @@ private void _UpdateScrollList()
228
228
{
229
229
_scrollNodeList = new List < TreeNode > ( ) ;
230
230
231
- int startNode = ( int ) ( _scrollIndex / ItemHeight ) - 1 ;
231
+ int startNode = ( int ) ( scrollIndex / ItemHeight ) - 1 ;
232
232
if ( startNode < 0 ) startNode = 0 ;
233
233
int nodesOnScreen = Height / ItemHeight + 3 ; // Magic number.
234
234
235
235
for ( int i = startNode ; i < startNode + nodesOnScreen && i < _nodeList . Count ; i ++ )
236
236
{
237
- if ( _nodeList [ i ] . Bounds . Y + _nodeList [ i ] . Bounds . Height > 0 && _nodeList [ i ] . Bounds . Y - ( int ) _scrollIndex < Height )
237
+ if ( _nodeList [ i ] . Bounds . Y + _nodeList [ i ] . Bounds . Height > 0 && _nodeList [ i ] . Bounds . Y - ( int ) scrollIndex < Height )
238
238
{
239
239
_scrollNodeList . Add ( _nodeList [ i ] ) ;
240
240
}
@@ -292,7 +292,7 @@ protected override void OnMouseDown(MouseEventArgs e)
292
292
var mclient = PointToClient ( MousePosition ) ;
293
293
294
294
_scroll = true ;
295
- _scrollStartY = mclient . Y - _scrollY ;
295
+ _scrollStartY = mclient . Y - _scrollbarY ;
296
296
return ;
297
297
}
298
298
@@ -305,7 +305,7 @@ protected override void OnMouseDown(MouseEventArgs e)
305
305
protected override void OnMouseHover ( EventArgs e )
306
306
{
307
307
var mclient = PointToClient ( MousePosition ) ;
308
- RectangleF _scrollRect = new RectangleF ( Width - _scrollWidth , _scrollY , _scrollWidth , _scrollHeight ) ;
308
+ RectangleF _scrollRect = new RectangleF ( Width - _scrollbarWidth , _scrollbarY , _scrollbarWidth , _scrollbarHeight ) ;
309
309
if ( _scrollRect . Contains ( mclient ) )
310
310
_scrollHovered = true ;
311
311
else
@@ -317,7 +317,7 @@ protected override void OnMouseMove(MouseEventArgs e)
317
317
{
318
318
var mclient = PointToClient ( MousePosition ) ;
319
319
320
- _scrollIndex = ( mclient . Y - _scrollStartY ) * ( _scroll_ItemsEstimatedHeigh / Height ) ;
320
+ scrollIndex = ( mclient . Y - _scrollStartY ) * ( _scroll_ItemsEstimatedHeigh / Height ) ;
321
321
322
322
_FixScrollIndex ( ) ;
323
323
_UpdateScrollList ( ) ;
@@ -334,7 +334,7 @@ protected override void OnMouseMove(MouseEventArgs e)
334
334
}
335
335
protected override void OnMouseWheel ( MouseEventArgs e )
336
336
{
337
- _scrollIndex -= e . Delta * ScrollSpeed ;
337
+ scrollIndex -= e . Delta * ScrollSpeed ;
338
338
339
339
_FixScrollIndex ( ) ;
340
340
_UpdateScrollList ( ) ;
@@ -359,11 +359,11 @@ protected override void OnPaint(PaintEventArgs e)
359
359
if ( _scrollHovered || _scroll ) _scrollColor = Color . FromArgb ( 136 , 136 , 136 ) ;
360
360
361
361
float _scrollYCoeff = Height / _scroll_ItemsEstimatedHeigh ;
362
- _scrollHeight = Height * _scrollYCoeff ;
363
- if ( _scrollHeight < 8 ) _scrollHeight = 8 ;
364
- _scrollY = _scrollIndex * _scrollYCoeff ;
362
+ _scrollbarHeight = Height * _scrollYCoeff ;
363
+ if ( _scrollbarHeight < 8 ) _scrollbarHeight = 8 ;
364
+ _scrollbarY = scrollIndex * _scrollYCoeff ;
365
365
366
- e . Graphics . FillRectangle ( new SolidBrush ( _scrollColor ) , Width - _scrollWidth + 2 , _scrollY , _scrollWidth - 2 , _scrollHeight ) ;
366
+ e . Graphics . FillRectangle ( new SolidBrush ( _scrollColor ) , Width - _scrollbarWidth + 2 , _scrollbarY , _scrollbarWidth - 2 , _scrollbarHeight ) ;
367
367
}
368
368
#endregion
369
369
0 commit comments