Draw animated image in TextBox
I want to draw an animated image in TextBox, i Google my problem, but i get some exam开发者_运维知识库ples about drawing a fixed image in TextBox like ExtRichTextBox.
Well if you can draw a fixed image as you say then animating it is simply a matter of changing that fixed image on some interval. I assume you can already do the fixed image bit, so simply setup a timer that will redraw the image using a new frame on some interval.
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 );
}
精彩评论