Animate a e.Graphics.DrawLine with arrowhead
I need to "animate" an arrow. It can go in any direction (up, down, left, right and diagonals) and the arrowhead will be at the end. It needs to appear as if it is growing from orgin to the end. To make matters more complicated it has to be in a user control so it is possible to add to the controls collection in the forms and remove it to delete it from the screen, and its background is really transparent (no color.transparent) so i can't paint the 开发者_开发百科background to "clear" the previous line. I have it static already (drawn from origin to end) but i can't animate it. I tried to add a timer in the user control but I fail to get a correct algorithm to calculate the intermediate ends of the line while it is growing. Any help would be appreciated. Thanks
When using animation on a Windows form you have to use another thread. Look into using a background worker: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
You don't need another thread - I have succesfully implemented Windows Forms animation.
My design:
- Use a Windows.System.Forms.Timer object to call a callback function 'Animate()' at regular intervals
- the Animate() function updates a property of your arrow, and then calls Invalidate() on the windows control
- this all happens in the same UI thread, so yuo will not get any flicker effects (as long as your control has double duffering switched on).
精彩评论