mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-03 18:44:54 +00:00
AnimationPictureBox - Fix animation starting when resizong
This commit is contained in:
27
PCK-Studio/Extensions/PictureBoxExtensions.cs
Normal file
27
PCK-Studio/Extensions/PictureBoxExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
internal static class PictureBoxExtensions
|
||||
{
|
||||
public static bool IsAnimating(this PictureBox pictureBox)
|
||||
{
|
||||
var fi = typeof(PictureBox).GetField("currentlyAnimating", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
return (bool)fi.GetValue(pictureBox);
|
||||
}
|
||||
|
||||
public static void Animate(this PictureBox pictureBox, bool animate)
|
||||
{
|
||||
var animateMethod = typeof(PictureBox).GetMethod("Animate", BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null, new Type[] { typeof(bool) }, null);
|
||||
animateMethod.Invoke(pictureBox, new object[] { animate });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions\MaterialContainerExtensions.cs" />
|
||||
<Compile Include="Extensions\PictureBoxExtensions.cs" />
|
||||
<Compile Include="Extensions\TreeViewExtensions.cs" />
|
||||
<Compile Include="Forms\Additional-Popups\FilterPrompt.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
@@ -34,37 +34,38 @@ namespace PckStudio.ToolboxItems
|
||||
|
||||
private bool _isPlaying;
|
||||
|
||||
private void PictureBox_Internal_Animate(PictureBox pictureBox, bool animate)
|
||||
{
|
||||
var animateMethod = typeof(PictureBox).GetMethod("Animate",
|
||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
|
||||
null, new Type[] { typeof(bool) }, null);
|
||||
animateMethod.Invoke(pictureBox, new object[] { animate });
|
||||
}
|
||||
|
||||
public new Image Image
|
||||
{
|
||||
get => base.Image;
|
||||
set
|
||||
{
|
||||
base.Image = value;
|
||||
PictureBox_Internal_Animate(this, false);
|
||||
this.Animate(false);
|
||||
if (value is null)
|
||||
return;
|
||||
value.SelectActiveFrame(new FrameDimension(value.FrameDimensionsList[0]), 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs paintEventArgs)
|
||||
{
|
||||
base.OnPaint(paintEventArgs);
|
||||
if (!_isPlaying && this.IsAnimating())
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_isPlaying = true;
|
||||
PictureBox_Internal_Animate(this, _isPlaying);
|
||||
this.Animate(_isPlaying);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_isPlaying = false;
|
||||
PictureBox_Internal_Animate(this, _isPlaying);
|
||||
this.Animate(_isPlaying);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
Reference in New Issue
Block a user