@@ -35,8 +35,6 @@ class ToolTipForm : Form
3535 int _topOffset ; // Might be trying to move the tooltip out of the way of Excel's tip - we track this extra offset here
3636 int ? _listLeft ;
3737 // Various graphics object cached
38- Brush _textBrush ;
39- Brush _linkBrush ;
4038 Color _textColor ;
4139 Color _linkColor ;
4240 Pen _borderPen ;
@@ -61,11 +59,9 @@ public ToolTipForm(IntPtr hwndOwner)
6159 { FontStyle . Bold | FontStyle . Italic , new Font ( "Segoe UI" , 9 , FontStyle . Bold | FontStyle . Italic ) } ,
6260
6361 } ;
64- //_textBrush = new SolidBrush( Color.FromArgb(68, 68, 68)); // Best matches Excel's built-in color, but I think a bit too light
65- _textColor = Color . FromArgb ( 60 , 60 , 60 ) ;
62+ // Color.FromArgb(68, 68, 68) Best matches Excel's built-in color, but I think a bit too light
63+ _textColor = Color . FromArgb ( 68 , 68 , 68 ) ;
6664 _linkColor = Color . Blue ;
67- _textBrush = new SolidBrush ( _textColor ) ;
68- _linkBrush = new SolidBrush ( _linkColor ) ;
6965 _borderPen = new Pen ( Color . FromArgb ( 195 , 195 , 195 ) ) ;
7066 _borderLightPen = new Pen ( Color . FromArgb ( 225 , 225 , 225 ) ) ;
7167 SetStyle ( ControlStyles . UserMouse | ControlStyles . UserPaint | ControlStyles . AllPaintingInWmPaint , true ) ;
@@ -315,23 +311,8 @@ Point GetMouseLocation(IntPtr lParam)
315311 #endregion
316312
317313 #region Painting
318-
319- bool oldPaint = false ;
320-
321314 protected override void OnPaint ( PaintEventArgs e )
322315 {
323- //if (oldPaint)
324- //{
325- // OnPaint_Plus(e);
326- // return;
327- //}
328- if ( oldPaint )
329- {
330- _textBrush = Brushes . Red ;
331- _linkBrush = Brushes . Pink ;
332- OnPaint_Plus ( e ) ;
333- }
334-
335316 base . OnPaint ( e ) ;
336317
337318 List < int > lineWidths = new List < int > ( ) ;
@@ -362,22 +343,19 @@ protected override void OnPaint(PaintEventArgs e)
362343 {
363344 // We support only a single link, for now
364345 Font font ;
365- Brush brush ;
366346 Color color ;
367347 if ( run . IsLink && _linkActive )
368348 {
369349 font = _fonts [ FontStyle . Underline ] ;
370- color = _linkColor ;
371- brush = _linkBrush ;
350+ color = _linkColor ; C : \Work \Excel - DNA \IntelliSense \Source\ExcelDna. IntelliSense. Host\ExcelDna. IntelliSense. Host- AddIn. xll. config
372351 }
373352 else
374353 {
375354 font = _fonts [ run . Style] ;
376355 color = _textColor ;
377- brush = _textBrush ;
378356 }
379357
380- foreach ( var text in getRunParts ( run . Text ) ) // Might split on space too?
358+ foreach ( var text in GetRunParts ( run . Text ) ) // Might split on space too?
381359 {
382360 if ( text == "" ) continue ;
383361
@@ -388,17 +366,22 @@ protected override void OnPaint(PaintEventArgs e)
388366 {
389367 // Draw it in this line
390368 TextRenderer . DrawText ( e . Graphics , text , font , new Point ( layoutLeft + lineWidth , layoutTop + currentHeight ) , color , textFormatFlags ) ;
369+ lineWidth += textSize . Width ; // + 1;
391370 }
392371 else
393372 {
394- // Make a new line and definitely draw it there (maybe with ellipses?)
395- lineWidths . Add ( lineWidth ) ;
396- currentHeight += lineHeight ;
397- currentHeight += linePadding ;
398-
399- lineHeight = minLineHeight ;
400- lineWidth = 2 ; // Little bit of indent on these lines
373+ if ( lineWidth > 0 ) // Check if we aren't on the first line, and already overflowing - might then line-break rather than ellipses...
374+ {
375+ // Make a new line and definitely draw it there (maybe with ellipses?)
376+ lineWidths . Add ( lineWidth ) ;
377+ currentHeight += lineHeight ;
378+ currentHeight += linePadding ;
379+
380+ lineHeight = minLineHeight ;
381+ lineWidth = 2 ; // Little bit of indent on these lines
382+ }
401383 TextRenderer . DrawText ( e . Graphics , text , font , new Rectangle ( layoutLeft + lineWidth , layoutTop + currentHeight , maxWidth , maxHeight - currentHeight ) , color , textFormatFlags |= TextFormatFlags . EndEllipsis ) ;
384+ lineWidth += Math . Min ( textSize . Width , maxWidth ) ; // + 1;
402385 }
403386
404387 if ( run . IsLink )
@@ -407,7 +390,6 @@ protected override void OnPaint(PaintEventArgs e)
407390 _linkAddress = run . LinkAddress ;
408391 }
409392
410- lineWidth += textSize . Width ; // + 1;
411393 lineHeight = Math . Max ( lineHeight , textSize . Height ) ;
412394 }
413395 }
@@ -422,7 +404,7 @@ protected override void OnPaint(PaintEventArgs e)
422404 DrawRoundedRectangle ( e . Graphics , new RectangleF ( 0 , 0 , Width - 1 , Height - 1 ) , 2 , 2 ) ;
423405 }
424406
425- IEnumerable < string > getRunParts ( string runText )
407+ static IEnumerable < string > GetRunParts ( string runText )
426408 {
427409 int lastStart = 0 ;
428410 for ( int i = 0 ; i < runText . Length ; i ++ )
@@ -436,106 +418,6 @@ IEnumerable<string> getRunParts(string runText)
436418 yield return runText . Substring ( lastStart ) ;
437419 }
438420
439- #region This is the original text painting, based on GDI+ calls
440- protected void OnPaint_Plus ( PaintEventArgs e )
441- {
442- const int leftPadding = 6 ;
443- const int linePadding = 0 ;
444- const int widthPadding = 12 ;
445- const int heightPadding = 2 ;
446-
447- base . OnPaint ( e ) ;
448- List < int > lineWidths = new List < int > ( ) ;
449- int totalWidth = 0 ;
450- int totalHeight = 0 ;
451-
452- using ( StringFormat format =
453- ( StringFormat ) StringFormat . GenericTypographic . Clone ( ) )
454- {
455- int layoutLeft = ClientRectangle . Location . X + leftPadding ;
456- int layoutTop = ClientRectangle . Location . Y ;
457- Rectangle layoutRect = new Rectangle ( layoutLeft , layoutTop - 1 , 1000 , 500 ) ;
458-
459- format . FormatFlags |= StringFormatFlags . MeasureTrailingSpaces ;
460- Size textSize ;
461-
462- foreach ( var line in _text )
463- {
464- totalHeight += linePadding ;
465- int lineHeight = 16 ;
466- foreach ( var run in line )
467- {
468- // We support only a single link, for now
469-
470- Font font ;
471- Brush brush ;
472- if ( run . IsLink && _linkActive )
473- {
474- font = _fonts [ FontStyle . Underline ] ;
475- brush = _linkBrush ;
476- }
477- else
478- {
479- font = _fonts [ run . Style ] ;
480- brush = _textBrush ;
481- }
482-
483- // TODO: Empty strings are a problem....
484- var text = run . Text == "" ? " " : run . Text ;
485-
486- DrawString_Plus ( e . Graphics , brush , ref layoutRect , out textSize , format , text , font ) ;
487-
488- if ( run . IsLink )
489- {
490- _linkClientRect = new Rectangle ( layoutRect . X - textSize . Width , layoutRect . Y , textSize . Width , textSize . Height ) ;
491- _linkAddress = run . LinkAddress ;
492- }
493-
494- totalWidth += textSize . Width ;
495- lineHeight = Math . Max ( lineHeight , textSize . Height ) ;
496-
497- // Pad by one extra pixel between runs, until we figure out kerning between runs
498- layoutRect . X += 1 ;
499- totalWidth += 1 ;
500- }
501- lineWidths . Add ( totalWidth ) ;
502- totalWidth = 0 ;
503- totalHeight += lineHeight ;
504- layoutRect = new Rectangle ( layoutLeft , layoutTop + totalHeight - 1 , 1000 , 500 ) ;
505- }
506- }
507- var width = lineWidths . Max ( ) + widthPadding ;
508- var height = totalHeight + heightPadding ;
509-
510- UpdateLocation ( width , height ) ;
511- DrawRoundedRectangle ( e . Graphics , new RectangleF ( 0 , 0 , Width - 1 , Height - 1 ) , 2 , 2 ) ;
512- }
513-
514- void DrawString_Plus ( Graphics g , Brush brush , ref Rectangle rect , out Size used ,
515- StringFormat format , string text , Font font )
516- {
517- using ( StringFormat copy = ( StringFormat ) format . Clone ( ) )
518- {
519- copy . SetMeasurableCharacterRanges ( new CharacterRange [ ]
520- {
521- new CharacterRange ( 0 , text . Length )
522- } ) ;
523- Region [ ] regions = g . MeasureCharacterRanges ( text , font , rect , copy ) ;
524-
525- g . DrawString ( text , font , brush , rect , format ) ;
526-
527- int height = ( int ) ( regions [ 0 ] . GetBounds ( g ) . Height ) ;
528- int width = ( int ) ( regions [ 0 ] . GetBounds ( g ) . Width ) ;
529-
530- // First just one line...
531- used = new Size ( width , height ) ;
532-
533- rect . X += width ;
534- rect . Width -= width ;
535- }
536- }
537- #endregion
538-
539421 void DrawRoundedRectangle ( Graphics g , RectangleF r , float radiusX , float radiusY )
540422 {
541423 var oldMode = g . SmoothingMode ;
0 commit comments