add Harmony patches for Telerik UI
This commit is contained in:
11
Pilz.UI.Telerik/Patches/Patches.cs
Normal file
11
Pilz.UI.Telerik/Patches/Patches.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace Pilz.UI.Telerik.Patches;
|
||||
|
||||
public static class Patches
|
||||
{
|
||||
public static void Initialize(Harmony harmony)
|
||||
{
|
||||
harmony.PatchAll();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Lib.Harmony" Version="2.3.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Telerik.UI.for.WinForms.AllControls" Version="2024.2.514">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
Reference in New Issue
Block a user