Asmodeus999

I want a picturebox to move down 1 pixel each time the timer ticks once, how would I do this I have tried several ways but failed.

Re: Visual Basic General Move PictureBox with a timer.

Matt_Fomich

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

PictureBox1.Top += 1

End Sub





Re: Visual Basic General Move PictureBox with a timer.

Matt_Fomich

Do you mean move down, or scroll down one pixel



Re: Visual Basic General Move PictureBox with a timer.

Matt_Fomich

Hey, there is no set-able scrollbar property. Man, what an incomplete control! Hopefully the .Net Framework v. 3 will have a more controllable picturebox.

Anyway, the easiest way to do this is probably to use a vertical scroll bar, and a panel. Put the picture box in the panel, set picture box border style to none, size mode normal, and resize it to the image that loads. Add a panel, set panel border to 3d, resize panel to same as picture box, and then change picture box.top value when the scroll bar value changes. Then change scrollbar value in timer tick event.

Private DockTop As Integer

Private Sub MovePicBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

DockTop = PictureBox1.Top

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

' Make sure part of picture box is still viewable before scrolling it.

If Math.Abs(PictureBox1.Top + DockTop) + 1 > DockTop AndAlso VScrollBar1.Value < VScrollBar1.Maximum Then

VScrollBar1.Value += 1

End If

End Sub

Private Sub VScrollBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBar1.ValueChanged

PictureBox1.Top = DockTop - VScrollBar1.Value

End Sub

Private Sub btnStartStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartStop.Click

Timer1.Enabled = Not Timer1.Enabled

End Sub

This is not deployment strength as is, but it gets the job done. Hope this helps.