@@ -14,6 +14,7 @@ namespace ExcelDna.IntelliSense
1414 class ToolTipForm : Form
1515 {
1616 FormattedText _text ;
17+ int _linePrefixWidth ;
1718 System . ComponentModel . IContainer components ;
1819 Win32Window _owner ;
1920 // Help Link
@@ -110,10 +111,12 @@ void ShowToolTip()
110111 }
111112 }
112113
113- public void ShowToolTip ( FormattedText text , int left , int top , int topOffset , int ? listLeft = null )
114+ public void ShowToolTip ( FormattedText text , string linePrefix , int left , int top , int topOffset , int ? listLeft = null )
114115 {
115116 Debug . Print ( $ "@@@ ShowToolTip - Old TopOffset: { _topOffset } , New TopOffset: { topOffset } ") ;
116117 _text = text ;
118+ _linePrefixWidth = MeasureFormulaStringWidth ( linePrefix ) ;
119+ left += _linePrefixWidth ;
117120 if ( left != _showLeft || top != _showTop || topOffset != _topOffset || listLeft != _listLeft )
118121 {
119122 // Update the start position and the current position
@@ -126,21 +129,22 @@ public void ShowToolTip(FormattedText text, int left, int top, int topOffset, in
126129 }
127130 if ( ! Visible )
128131 {
129- Debug . Print ( $ "ShowToolTip - Showing ToolTipForm: { _text . ToString ( ) } ") ;
132+ Debug . Print ( $ "ShowToolTip - Showing ToolTipForm: { linePrefix } => { _text . ToString ( ) } ") ;
130133 // Make sure we're in the right position before we're first shown
131134 SetBounds ( _currentLeft , _currentTop + _topOffset , 0 , 0 ) ;
132135 ShowToolTip ( ) ;
133136 }
134137 else
135138 {
136- Debug . Print ( $ "ShowToolTip - Invalidating ToolTipForm: { _text . ToString ( ) } ") ;
139+ Debug . Print ( $ "ShowToolTip - Invalidating ToolTipForm: { linePrefix } => { _text . ToString ( ) } ") ;
137140 Invalidate ( ) ;
138141 }
139142 }
140143
141144 public void MoveToolTip ( int left , int top , int topOffset , int ? listLeft = null )
142145 {
143146 Debug . Print ( $ "@@@ MoveToolTip - Old TopOffset: { _topOffset } , New TopOffset: { topOffset } ") ;
147+ left += _linePrefixWidth ;
144148 // We might consider checking the new position against earlier mouse movements
145149 _currentLeft = left ;
146150 _currentTop = top ;
@@ -175,6 +179,17 @@ public IntPtr OwnerHandle
175179 }
176180 }
177181
182+ // TODO: Move or clean up or something...
183+ Font StandardFont = new Font ( "Calibri" , 11 ) ;
184+ int MeasureFormulaStringWidth ( string formulaString )
185+ {
186+ if ( string . IsNullOrEmpty ( formulaString ) )
187+ return 0 ;
188+
189+ var size = TextRenderer . MeasureText ( formulaString , StandardFont ) ;
190+ return size . Width ;
191+ }
192+
178193 #region Mouse Handling
179194
180195 void MouseButtonDown ( Point screenLocation )
@@ -329,6 +344,7 @@ protected override void OnPaint(PaintEventArgs e)
329344 }
330345 var width = lineWidths . Max ( ) + widthPadding ;
331346 var height = totalHeight + heightPadding ;
347+
332348 UpdateLocation ( width , height ) ;
333349 DrawRoundedRectangle ( e . Graphics , new RectangleF ( 0 , 0 , Width - 1 , Height - 1 ) , 2 , 2 ) ;
334350 }
0 commit comments