-
Mar 10th, 2017, 03:14 PM
#1
Thread Starter
New Member
VB PictureBox Movement
I am in need of assistance with creating a code to move a picturebox left to right based on the integer put into my text box
Example: I input 2 it moves to the left and then the right (twice)
Do I have to add a timer first? Or can I just make a code something like if picturebox = x integer then move picturebox x times
I know its not the right format but to get a better idea of it.
Can someone show me where to start? Maybe a example I like to see it physically.
-
Mar 10th, 2017, 04:26 PM
#2
Hyperactive Member
Re: VB PictureBox Movement
You will need a TextBox1 and a PictureBox1 for these codes to work.
If you input 5 into the textbox the picturebox will move 5pix to the left x2 then 5pix to the right x2 there is a .5 sec delay between the movements.
vb.net Code:
Imports System.Threading Public Class Form1 Sub Delay(ByVal i As Double) Dim TotalMS As Integer If i.ToString.Contains(".") Then Dim BeforeDecVal As String = i .ToString.Split("."c )(0) Dim AfterDecVal As String = i .ToString.Split("."c )(1) TotalMS = CInt(CDbl(AfterDecVal) * 100 + CDbl(BeforeDecVal) * 1000) Else TotalMS = CInt(i * 1000) End If Using w As New ManualResetEvent(False) w.WaitOne(TotalMS) End Using End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged If TextBox1.Text IsNot Nothing AndAlso CInt(TextBox1.Text) > 0 Then Delay(0.5) PictureBox1.Location = New Point(PictureBox1.Location.X - CInt(TextBox1.Text), PictureBox1.Location.Y) Delay(0.5) PictureBox1.Location = New Point(PictureBox1.Location.X - CInt(TextBox1.Text), PictureBox1.Location.Y) Delay(0.5) PictureBox1.Location = New Point(PictureBox1.Location.X + CInt(TextBox1.Text), PictureBox1.Location.Y) Delay(0.5) PictureBox1.Location = New Point(PictureBox1.Location.X + CInt(TextBox1.Text), PictureBox1.Location.Y) End If End If End Sub End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|