From 0690b53def0c77ffa83781ea75fb557ba9754dd2 Mon Sep 17 00:00:00 2001 From: kushan <9400651+kushanp@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:04:42 +0100 Subject: [PATCH 1/3] Remove the link handling event handlers when disposing HtmlToolTip --- Source/HtmlRenderer.WinForms/HtmlToolTip.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/HtmlRenderer.WinForms/HtmlToolTip.cs b/Source/HtmlRenderer.WinForms/HtmlToolTip.cs index 9b6bb1eb8..8bd668cb2 100644 --- a/Source/HtmlRenderer.WinForms/HtmlToolTip.cs +++ b/Source/HtmlRenderer.WinForms/HtmlToolTip.cs @@ -406,23 +406,22 @@ protected virtual void OnToolTipDisposed(EventArgs e) Draw -= OnToolTipDraw; Disposed -= OnToolTipDisposed; + if (_linkHandlingTimer != null) + { + _linkHandlingTimer.Tick -= OnLinkHandlingTimerTick; + _linkHandlingTimer.Dispose(); + _linkHandlingTimer = null; + } + if (_htmlContainer != null) { + _htmlContainer.LinkClicked -= OnLinkClicked; _htmlContainer.RenderError -= OnRenderError; _htmlContainer.StylesheetLoad -= OnStylesheetLoad; _htmlContainer.ImageLoad -= OnImageLoad; _htmlContainer.Dispose(); _htmlContainer = null; } - - if (_linkHandlingTimer != null) - { - _linkHandlingTimer.Dispose(); - _linkHandlingTimer = null; - - if (_htmlContainer != null) - _htmlContainer.LinkClicked -= OnLinkClicked; - } } From 533e90500d3cccc6c12fbac5358cc0e9cde8fd1f Mon Sep 17 00:00:00 2001 From: kushan <9400651+kushanp@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:05:10 +0100 Subject: [PATCH 2/3] Use pointer sized handles in the Win32 P/Invoke signatures --- Source/HtmlRenderer.WinForms/HtmlLabel.cs | 2 +- Source/HtmlRenderer.WinForms/HtmlPanel.cs | 2 +- .../MetafileExtensions.cs | 18 +++++++++--------- .../Utilities/Win32Utils.cs | 7 ++++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/HtmlRenderer.WinForms/HtmlLabel.cs b/Source/HtmlRenderer.WinForms/HtmlLabel.cs index 254566541..2fafa39e6 100644 --- a/Source/HtmlRenderer.WinForms/HtmlLabel.cs +++ b/Source/HtmlRenderer.WinForms/HtmlLabel.cs @@ -708,7 +708,7 @@ protected override void WndProc(ref Message m) try { // Replace .NET's hand cursor with the OS cursor - Win32Utils.SetCursor(Win32Utils.LoadCursor(0, Win32Utils.IdcHand)); + Win32Utils.SetCursor(Win32Utils.LoadCursor(IntPtr.Zero, (IntPtr)Win32Utils.IdcHand)); m.Result = IntPtr.Zero; return; } diff --git a/Source/HtmlRenderer.WinForms/HtmlPanel.cs b/Source/HtmlRenderer.WinForms/HtmlPanel.cs index 9d150fd19..91c331fbf 100644 --- a/Source/HtmlRenderer.WinForms/HtmlPanel.cs +++ b/Source/HtmlRenderer.WinForms/HtmlPanel.cs @@ -798,7 +798,7 @@ protected override void WndProc(ref Message m) try { // Replace .NET's hand cursor with the OS cursor - Win32Utils.SetCursor(Win32Utils.LoadCursor(0, Win32Utils.IdcHand)); + Win32Utils.SetCursor(Win32Utils.LoadCursor(IntPtr.Zero, (IntPtr)Win32Utils.IdcHand)); m.Result = IntPtr.Zero; return; } diff --git a/Source/HtmlRenderer.WinForms/MetafileExtensions.cs b/Source/HtmlRenderer.WinForms/MetafileExtensions.cs index 7bc5fad25..a4c1f8768 100644 --- a/Source/HtmlRenderer.WinForms/MetafileExtensions.cs +++ b/Source/HtmlRenderer.WinForms/MetafileExtensions.cs @@ -14,24 +14,24 @@ public static void SaveAsEmf(Metafile me, string fileName) by : SWAT Team member _1 Date : Friday, February 01, 2008 1:38 PM */ - int enfMetafileHandle = me.GetHenhmetafile().ToInt32(); - int bufferSize = GetEnhMetaFileBits(enfMetafileHandle, 0, null); // Get required buffer size. - byte[] buffer = new byte[bufferSize]; // Allocate sufficient buffer - if (GetEnhMetaFileBits(enfMetafileHandle, bufferSize, buffer) <= 0) // Get raw metafile data. + IntPtr enfMetafileHandle = me.GetHenhmetafile(); + uint bufferSize = GetEnhMetaFileBits(enfMetafileHandle, 0, null); // Get required buffer size. + byte[] buffer = new byte[bufferSize]; // Allocate sufficient buffer + if (GetEnhMetaFileBits(enfMetafileHandle, bufferSize, buffer) == 0) // Get raw metafile data. throw new SystemException("Fail"); FileStream ms = File.Open(fileName, FileMode.Create); - ms.Write(buffer, 0, bufferSize); + ms.Write(buffer, 0, buffer.Length); ms.Close(); ms.Dispose(); if (!DeleteEnhMetaFile(enfMetafileHandle)) //free handle throw new SystemException("Fail Free"); } - [DllImport("gdi32")] - public static extern int GetEnhMetaFileBits(int hemf, int cbBuffer, byte[] lpbBuffer); + [DllImport("gdi32.dll")] + public static extern uint GetEnhMetaFileBits(IntPtr hemf, uint cbBuffer, byte[] lpbBuffer); - [DllImport("gdi32")] - public static extern bool DeleteEnhMetaFile(int hemfbitHandle); + [DllImport("gdi32.dll")] + public static extern bool DeleteEnhMetaFile(IntPtr hemf); } } diff --git a/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs b/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs index 228e47658..201e3f3ab 100644 --- a/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs +++ b/Source/HtmlRenderer.WinForms/Utilities/Win32Utils.cs @@ -48,10 +48,11 @@ internal static class Win32Utils public const int TextAlignBaselineRtl = 256 + 24; [DllImport("user32.dll")] - public static extern int SetCursor(int hCursor); + public static extern IntPtr SetCursor(IntPtr hCursor); - [DllImport("user32.dll")] - public static extern int LoadCursor(int hInstance, int lpCursorName); + // The cursor name is a pointer, a predefined cursor like IdcHand is an ID cast to one + [DllImport("user32.dll", EntryPoint = "LoadCursorW")] + public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); /// /// Create a compatible memory HDC from the given HDC.
From e93e8e4da7a6b0ab1bf8b461f0c1e7a282ee5446 Mon Sep 17 00:00:00 2001 From: kushan <9400651+kushanp@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:05:24 +0100 Subject: [PATCH 3/3] Don't show the HTML tooltip for a window that isn't a control --- Source/HtmlRenderer.WinForms/HtmlToolTip.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/HtmlRenderer.WinForms/HtmlToolTip.cs b/Source/HtmlRenderer.WinForms/HtmlToolTip.cs index 8bd668cb2..7de567f96 100644 --- a/Source/HtmlRenderer.WinForms/HtmlToolTip.cs +++ b/Source/HtmlRenderer.WinForms/HtmlToolTip.cs @@ -238,6 +238,13 @@ public virtual Size MaximumSize ///
protected virtual void OnToolTipPopup(PopupEventArgs e) { + // Shown for a window that isn't a control, there's no control to measure the html with + if (e.AssociatedControl == null) + { + e.Cancel = true; + return; + } + //Create fragment container var cssClass = string.IsNullOrEmpty(_tooltipCssClass) ? null : string.Format(" class=\"{0}\"", _tooltipCssClass); var toolipHtml = string.Format("{1}", cssClass, GetToolTip(e.AssociatedControl));