From 88921d2a4ec6b3e2d79dfcdf553ad43d1c30b0c3 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 20 May 2025 07:56:05 +0200 Subject: [PATCH] add patch for stretching issue on AutoSize of RadTextBoxControl --- Pilz.UI.Telerik/Patches/Patches.cs | 3 +- ...BoxControl_PreventAutoStretchOnAutoSize.cs | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Pilz.UI.Telerik/Patches/TelerikUiForWinForms/RadTextBoxControl_PreventAutoStretchOnAutoSize.cs diff --git a/Pilz.UI.Telerik/Patches/Patches.cs b/Pilz.UI.Telerik/Patches/Patches.cs index aa29660..a6e76bd 100644 --- a/Pilz.UI.Telerik/Patches/Patches.cs +++ b/Pilz.UI.Telerik/Patches/Patches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using System.Reflection; namespace Pilz.UI.Telerik.Patches; @@ -6,6 +7,6 @@ public static class Patches { public static void Initialize(Harmony harmony) { - harmony.PatchAll(); + harmony.PatchAll(Assembly.GetExecutingAssembly()); } } diff --git a/Pilz.UI.Telerik/Patches/TelerikUiForWinForms/RadTextBoxControl_PreventAutoStretchOnAutoSize.cs b/Pilz.UI.Telerik/Patches/TelerikUiForWinForms/RadTextBoxControl_PreventAutoStretchOnAutoSize.cs new file mode 100644 index 0000000..140d66f --- /dev/null +++ b/Pilz.UI.Telerik/Patches/TelerikUiForWinForms/RadTextBoxControl_PreventAutoStretchOnAutoSize.cs @@ -0,0 +1,41 @@ +using HarmonyLib; +using System.Reflection; +using Telerik.WinControls; +using Telerik.WinControls.UI; + +namespace Pilz.UI.Telerik.Patches.TelerikUiForWinForms; + +[HarmonyPatch(typeof(RadTextBoxControl))] +[HarmonyPatch("ProcessAutoSizeChanged")] +internal class RadTextBoxControl_PreventAutoStretchOnAutoSize +{ + private static readonly MethodInfo m_get_RootElement = AccessTools.PropertyGetter(typeof(RadControl), nameof(RadControl.RootElement)); + + public static IEnumerable Transpiler(IEnumerable instructions) + { + var ignored = 0; + var ignoring = false; + int getRootelementCallcount = 0; + + foreach (var instruction in instructions) + { + if (instruction.Calls(m_get_RootElement)) + { + getRootelementCallcount += 1; + if (getRootelementCallcount == 2) + ignoring = true; + } + if (ignoring) + { + if (ignored >= 4) + ignoring = false; + else + { + ignored += 1; + continue; + } + } + yield return instruction; + } + } +}