@@ -31,17 +31,17 @@ public class HtmlToolTip : ToolTip
3131 /// <summary>
3232 /// the container to render and handle the html shown in the tooltip
3333 /// </summary>
34- protected HtmlContainer _htmlContainer ;
34+ protected HtmlContainer ? _htmlContainer ;
3535
3636 /// <summary>
3737 /// the raw base stylesheet data used in the control
3838 /// </summary>
39- protected string _baseRawCssData ;
39+ protected string ? _baseRawCssData ;
4040
4141 /// <summary>
4242 /// the base stylesheet data used in the panel
4343 /// </summary>
44- protected CssData _baseCssData ;
44+ protected CssData ? _baseCssData ;
4545
4646 /// <summary>
4747 /// The text rendering hint to be used for text rendering.
@@ -57,13 +57,13 @@ public class HtmlToolTip : ToolTip
5757 /// the control that the tooltip is currently showing on.<br/>
5858 /// Used for link handling.
5959 /// </summary>
60- private Control _associatedControl ;
60+ private Control ? _associatedControl ;
6161
6262 /// <summary>
6363 /// timer used to handle mouse move events when mouse is over the tooltip.<br/>
6464 /// Used for link handling.
6565 /// </summary>
66- private Timer _linkHandlingTimer ;
66+ private Timer ? _linkHandlingTimer ;
6767
6868 /// <summary>
6969 /// the handle of the actual tooltip window used to know when the tooltip is hidden<br/>
@@ -175,7 +175,7 @@ public TextRenderingHint TextRenderingHint
175175 [ Description ( "Set base stylesheet to be used by html rendered in the tooltip." ) ]
176176 [ Category ( "Appearance" ) ]
177177 [ DesignerSerializationVisibility ( DesignerSerializationVisibility . Visible ) ]
178- [ Editor ( "System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2 .0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a " , "System.Drawing.Design.UITypeEditor, System.Drawing , Version=2 .0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a " ) ]
178+ [ Editor ( "System.ComponentModel.Design.MultilineStringEditor, System.Windows.Forms. Design, Version=10 .0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 " , "System.Drawing.Design.UITypeEditor, System.Windows.Forms , Version=10 .0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 " ) ]
179179 public virtual string BaseStylesheet
180180 {
181181 get { return _baseRawCssData ; }
@@ -238,6 +238,9 @@ public virtual Size MaximumSize
238238 /// </summary>
239239 protected virtual void OnToolTipPopup ( PopupEventArgs e )
240240 {
241+ if ( e . AssociatedControl == null )
242+ return ;
243+
241244 //Create fragment container
242245 var cssClass = string . IsNullOrEmpty ( _tooltipCssClass ) ? null : string . Format ( " class=\" {0}\" " , _tooltipCssClass ) ;
243246 var toolipHtml = string . Format ( "<div{0}>{1}</div>" , cssClass , GetToolTip ( e . AssociatedControl ) ) ;
@@ -276,7 +279,8 @@ protected virtual void OnToolTipDraw(DrawToolTipEventArgs e)
276279 _tooltipHandle = Win32Utils . WindowFromDC ( hdc ) ;
277280 e . Graphics . ReleaseHdc ( hdc ) ;
278281
279- AdjustTooltipPosition ( e . AssociatedControl , e . Bounds . Size ) ;
282+ if ( e . AssociatedControl != null )
283+ AdjustTooltipPosition ( e . AssociatedControl , e . Bounds . Size ) ;
280284 }
281285
282286 e . Graphics . Clear ( Color . White ) ;
@@ -373,16 +377,19 @@ protected virtual void OnLinkHandlingTimerTick(EventArgs e)
373377 _linkHandlingTimer . Stop ( ) ;
374378 _tooltipHandle = IntPtr . Zero ;
375379
376- var mPos = Control . MousePosition ;
377- var mButtons = Control . MouseButtons ;
378- var rect = Win32Utils . GetWindowRectangle ( handle ) ;
379- if ( rect . Contains ( mPos ) )
380+ if ( handle != IntPtr . Zero && _associatedControl != null )
380381 {
381- if ( mButtons == MouseButtons . Left )
382+ var mPos = Control . MousePosition ;
383+ var mButtons = Control . MouseButtons ;
384+ var rect = Win32Utils . GetWindowRectangle ( handle ) ;
385+ if ( rect . Contains ( mPos ) )
382386 {
383- var args = new MouseEventArgs ( mButtons , 1 , mPos . X - rect . X , mPos . Y - rect . Y , 0 ) ;
384- _htmlContainer . HandleMouseDown ( _associatedControl , args ) ;
385- _htmlContainer . HandleMouseUp ( _associatedControl , args ) ;
387+ if ( mButtons == MouseButtons . Left )
388+ {
389+ var args = new MouseEventArgs ( mButtons , 1 , mPos . X - rect . X , mPos . Y - rect . Y , 0 ) ;
390+ _htmlContainer . HandleMouseDown ( _associatedControl , args ) ;
391+ _htmlContainer . HandleMouseUp ( _associatedControl , args ) ;
392+ }
386393 }
387394 }
388395 }
@@ -402,23 +409,22 @@ protected virtual void OnToolTipDisposed(EventArgs e)
402409 Draw -= OnToolTipDraw ;
403410 Disposed -= OnToolTipDisposed ;
404411
412+ if ( _linkHandlingTimer != null )
413+ {
414+ _linkHandlingTimer . Tick -= OnLinkHandlingTimerTick ;
415+ _linkHandlingTimer . Dispose ( ) ;
416+ _linkHandlingTimer = null ;
417+ }
418+
405419 if ( _htmlContainer != null )
406420 {
421+ _htmlContainer . LinkClicked -= OnLinkClicked ;
407422 _htmlContainer . RenderError -= OnRenderError ;
408423 _htmlContainer . StylesheetLoad -= OnStylesheetLoad ;
409424 _htmlContainer . ImageLoad -= OnImageLoad ;
410425 _htmlContainer . Dispose ( ) ;
411426 _htmlContainer = null ;
412427 }
413-
414- if ( _linkHandlingTimer != null )
415- {
416- _linkHandlingTimer . Dispose ( ) ;
417- _linkHandlingTimer = null ;
418-
419- if ( _htmlContainer != null )
420- _htmlContainer . LinkClicked -= OnLinkClicked ;
421- }
422428 }
423429
424430
0 commit comments