@@ -252,35 +252,22 @@ public bool DrawDefault {
252252 protected virtual void DrawBackground ( DrawTreeNodeEventArgs e )
253253 {
254254 Graphics g = e . Graphics ;
255- int width = MeasureItemWidth ( e ) + 2 ;
255+ int width = MeasureItemWidth ( e ) ;
256256 Rectangle backRect = new Rectangle ( e . Bounds . X , e . Bounds . Y , width , e . Bounds . Height ) ;
257257
258- if ( ( e . State & ( TreeNodeStates . Selected | TreeNodeStates . Focused ) ) == TreeNodeStates . Selected ) {
258+ if ( ( e . State & SelectedAndFocused ) == TreeNodeStates . Selected ) {
259259 g . FillRectangle ( SystemBrushes . Control , backRect ) ;
260260 } else if ( ( e . State & TreeNodeStates . Selected ) == TreeNodeStates . Selected ) {
261261 g . FillRectangle ( SystemBrushes . Highlight , backRect ) ;
262+ ControlPaint . DrawFocusRectangle ( e . Graphics , backRect ) ;
262263 } else {
263264 g . FillRectangle ( SystemBrushes . Window , backRect ) ;
264265 }
265-
266- if ( ( e . State & TreeNodeStates . Focused ) == TreeNodeStates . Focused ) {
267- backRect . Width -- ;
268- backRect . Height -- ;
269- using ( Pen dottedPen = new Pen ( SystemColors . WindowText ) ) {
270- dottedPen . DashStyle = System . Drawing . Drawing2D . DashStyle . Dot ;
271- g . DrawRectangle ( dottedPen , backRect ) ;
272- Color h = SystemColors . Highlight ;
273- dottedPen . Color = Color . FromArgb ( 255 - h . R , 255 - h . G , 255 - h . B ) ;
274- dottedPen . DashOffset = 1 ;
275- g . DrawRectangle ( dottedPen , backRect ) ;
276- }
277- g . DrawLine ( SystemPens . WindowText , backRect . Right + 1 , backRect . Y , backRect . Right + 1 , backRect . Bottom ) ;
278- }
279266 }
280267
281268 protected virtual int MeasureItemWidth ( DrawTreeNodeEventArgs e )
282269 {
283- return MeasureTextWidth ( e . Graphics , Text , TreeView . Font ) ;
270+ return MeasureTextWidth ( e . Graphics , Text , e . Node . NodeFont ) ;
284271 }
285272
286273 protected virtual void DrawForeground ( DrawTreeNodeEventArgs e )
@@ -296,27 +283,22 @@ public void Draw(DrawTreeNodeEventArgs e)
296283 // Helper routines
297284 protected int MeasureTextWidth ( Graphics g , string text , Font font )
298285 {
299- SizeF size = g . MeasureString ( text , font ) ;
286+ var size = TextRenderer . MeasureText ( text , font ) ;
300287 return ( int ) size . Width ;
301288 }
302289
303290 const TreeNodeStates SelectedAndFocused = TreeNodeStates . Selected | TreeNodeStates . Focused ;
304291
305- protected void DrawText ( DrawTreeNodeEventArgs e , string text , Brush brush , Font font )
292+ protected void DrawText ( DrawTreeNodeEventArgs e , string text , Color color , Font font )
306293 {
307294 float x = e . Bounds . X ;
308- DrawText ( e , text , brush , font , ref x ) ;
295+ DrawText ( e , text , color , font , ref x ) ;
309296 }
310297
311- protected void DrawText ( DrawTreeNodeEventArgs e , string text , Brush brush , Font font , ref float x )
298+ protected void DrawText ( DrawTreeNodeEventArgs e , string text , Color color , Font font , ref float x )
312299 {
313- if ( ( e . State & SelectedAndFocused ) == SelectedAndFocused ) {
314- brush = SystemBrushes . HighlightText ;
315- }
316- e . Graphics . DrawString ( text , font , brush , new PointF ( x , e . Bounds . Y ) ) ;
317-
318- SizeF size = e . Graphics . MeasureString ( text , font ) ;
319- x += size . Width ;
300+ color = GetTextColor ( e . State , color ) ;
301+ TextRenderer . DrawText ( e . Graphics , text , font , new Point ( ( int ) x , e . Bounds . Y ) , color ) ;
320302 }
321303
322304 protected Color GetTextColor ( TreeNodeStates state , Color c )
@@ -353,7 +335,7 @@ public static Font ItalicMonospacedFont {
353335
354336 public static Font RegularDefaultFont {
355337 get {
356- return TreeView . DefaultFont ;
338+ return SystemFonts . MessageBoxFont ;
357339 }
358340 }
359341
0 commit comments