text animation
I want to make a flying banner.
If all you want is a marquee, then don't re-invent, just download marquee code, i'm sure you can get it on www.planetsourcecode.com
If you want a better looking one, then you'd have to make a Graphics object.
Here's an example, but note, you'll have to make animation code in the paint event, as i am just drawing text at the same place.
In my example, there's Form1, Button1, and PictureBox1. Button1 turns on/off the drawing.
Public Class Form1 Private Animating As Boolean Private MyText As String = "Hello" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Animating = Not Animating If Animating Then Me.PictureBox1.Invalidate() Else Me.PictureBox1.Refresh() End If End Sub Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint If Animating Then e.Graphics.DrawString(MyText, New Font("Comic Sans", 10, FontStyle.Italic), Brushes.Cyan, 0, 0) End If End Sub Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If Animating Then Me.PictureBox1.Invalidate() End Sub End Class |
Hope this helps !
basically, You have to animate the position of the text.
In the example, when you drawString, the last 2 arguements are X ands Y Position.
What you have to do is passs differnt values to the XY coords for earh letter.
If the String is "Hello", then...
H= (X=1,Y=1)
E= (X=10,5)
L= (X=15,10)
L= (X=20,5)
O= (X=25,Y=1)
THis would look like...
H O
E L
L
It's your responcibilty to move each letter on each animation frame.
If all you want is a flying banner, then you can probably get away with just cahnging the Y values, so the letters only move up and down.
And if you use (Y=Math.Sin() * the current time), then you'll get a Y value that moves up and down according to the current time.
Making your own animation is not easy. This is only the tip of the iceberg. You also have to take into consideration frame speeds, and looping, and so on.