111,129
社区成员
发帖
与我相关
我的任务
分享
)
using System;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication1
{
class MyGifBox : Control
{
Image img;
string path;
public string Path
{
get { return path; }
set { path = value; UpdatePath(); }
}
public MyGifBox() : base() { }
public MyGifBox(string src)
: base()
{
Path = src;
}
void UpdatePath()
{
img = Bitmap.FromFile(path);
if (img != null)
{
this.Width = img.Width;
this.Height = img.Height;
}
}
bool currentlyAnimating = false;
public void AnimateImage()
{
if (!currentlyAnimating)
{
ImageAnimator.Animate(img, new EventHandler(this.OnFrameChanged));
currentlyAnimating = true;
}
}
private void OnFrameChanged(object o, EventArgs e)
{
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
if (img == null)
return;
AnimateImage();
ImageAnimator.UpdateFrames();
e.Graphics.DrawImage(img, new Point(0, 0));
}
}
}
private void Form1_Shown(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
myExtRichTextBox1.InsertControl(new MyGifBox(@"E:\My Documents\My Pictures\39.gif"));
}