我想在TextBox中绘制一个动画图像,我想问我的问题,但我得到一些关于在TextBox中绘制固定图像的例子,如ExtRichTextBox。
答案 0 :(得分:1)
如果你可以像你说的那样绘制一个固定的图像,那么设置动画只是在某个时间间隔内更改固定图像的问题。我假设您已经可以执行固定图像位,因此只需设置一个计时器,该计时器将在某个时间间隔内使用新帧重绘图像。
private void SomeTimer_Tick( ... )
{
UpdateAnimation();
}
private int _frameCount;
private const int MaxFrames = //whatever, you need to determine this
private void UpdateAnimation()
{
_frameCount = (_frameCount + 1) % MaxFrames;
var image = GetFrame( _frameCount );
// draw the new frame
}
private const int FrameWidth = // again, you need to determine this
private const int FrameHeight = // again, you need to determine this
private Bitmap GetFrame( int frame )
{
// assumes frames are lined up horizontally on a sheet
var rect = new Rectangle( frame * FrameWidth, 0, FrameWidth, FrameHeight );
// you could create the frames up front to avoid many calls to Clone()
return MySpriteSheet.Clone( rect, MySpriteSheet.PixelFormat );
}