"Anagnos" <fr***********@yahoo.com> wrote in message news:57**************************@posting.google.c om...
Ok, i have a program where I need to animate images on a background.
However, the VB.NET CreateGraphics is not fast enough to do it without
flicker. I am not a very advanced programmer, and cannot figure out
how to use DX or API in VB.NET. Could someone give me some simple but
specific code that draws an image to the screen? Thanks.
How about something like this?
LFS
Private bar1 As Pen = New Pen(Color.Blue, 12)
Private bar2 As Pen = New Pen(Color.Red, 12)
Private buf As Bitmap
Private bufG As Graphics
Private center As Point
Private tip As Point
Private grx As Graphics
Private ang As Single
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
buf = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, Me.CreateGraphics)
bufG = Graphics.FromImage(buf)
center.X = Me.ClientSize.Width \ 2
center.Y = Me.ClientSize.Height \ 2
Timer1.Interval = 20
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If grx Is Nothing Then grx = Me.CreateGraphics
ang += 0.05!
If ang >= (2 * Math.PI) Then ang = 0
tip.X = CInt(Math.Sin(ang) * center.X * 0.6)
tip.Y = CInt(Math.Cos(ang) * center.Y * 0.6)
bufG.Clear(Color.White)
bufG.DrawLine(bar1, center.X, center.Y, center.X + tip.X, center.Y + tip.Y)
bufG.DrawEllipse(bar2, center.X - ang * 20, center.Y - ang * 20, ang * 40, ang * 40)
grx.DrawImageUnscaled(buf, 0, 0)
End Sub