add Harmony patches for Telerik UI

This commit is contained in:
2025-05-16 06:48:12 +02:00
parent 570e49ad76
commit 6f0bf4194b
3 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using HarmonyLib;
using Telerik.WinControls.UI;
namespace Pilz.UI.Telerik.Patches.TelerikUiForWinForms;
[HarmonyPatch(typeof(RadPictureBoxElement))]
[HarmonyPatch("PasteImage")]
public class RadPictureBoxElement_PasteImageFixes
{
private static readonly Dictionary<RadPictureBoxElement, Image> images = [];
public static void Prefix(object __instance)
{
if (__instance is RadPictureBoxElement pb)
{
// Remember our image
images.Remove(pb);
images.Add(pb, pb.Image);
}
}
public static void Postfix(object __instance)
{
if (__instance is RadPictureBoxElement pb && images.TryGetValue(pb, out var image) && pb.Image != image)
{
// Remove first to avoid conflicts on error
images.Remove(pb);
// Call "OnImageLoaded"
var method = typeof(RadPictureBoxElement).GetMethod("OnImageLoaded", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
method.Invoke(pb, null);
}
}
}