Moving Drawing

Andrew9000
05-16-2006, 10:41 PM
when you see my screenshot you will see the problem..

I want the picture to move across the screen and keep the background showing as normal.

How can I fix this

http://and-my-site.batcave.net/nonweb/vbnet_error.jpg

jo0ls
05-30-2006, 09:26 PM
You lost me with all that graphicsState stuff in the code in the picture.
From the msdn the save and restore methods of the Graphics class are used to save the state of the graphics object at a particular time. This does not save any drawing you have done. What it saves will be things like co-ordinate system alterations and probably stuff like anti-aliasing setting - not sure.

If you strip out all the stuff that isn't doing anything from your code then you have:

dim gfx as graphics = me.creategraphcis

and in the timer tick:
x+=1
gfx.drawimage(pict, x, y)

(also, no need to load the image from file continuously!)

Public Class Form1

Private rabbit As Bitmap
Private background As Bitmap
Private x As Integer
Private WithEvents t As Timer

Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()

rabbit = Bitmap.FromFile("c:\rabbit.png")
background = Bitmap.FromFile("C:\background.png")
Me.BackgroundImage = background
' try and reduce flicker:
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.UpdateStyles()
t = New Timer
t.Interval = 10
t.Start()
End Sub

Private Sub t_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles t.Tick
x += 1
If x > Me.Width Then x = -rabbit.Width
Me.Invalidate()
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImageUnscaled(rabbit, x, 0)
End Sub

End Class

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum