PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VB PictureBox Movement-VBForums
Results 1 to 2 of 2

Thread: VB PictureBox Movement

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    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.

  2. #2
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    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:
    1. Imports System.Threading
    2. Public Class Form1
    3.     Sub Delay(ByVal i As Double)
    4.         Dim TotalMS As Integer
    5.         If i.ToString.Contains(".") Then
    6.             Dim BeforeDecVal As String = i.ToString.Split("."c)(0)
    7.             Dim AfterDecVal As String = i.ToString.Split("."c)(1)
    8.             TotalMS = CInt(CDbl(AfterDecVal) * 100 + CDbl(BeforeDecVal) * 1000)
    9.         Else
    10.             TotalMS = CInt(i * 1000)
    11.         End If
    12.         Using w As New ManualResetEvent(False)
    13.             w.WaitOne(TotalMS)
    14.         End Using
    15.     End Sub
    16.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    17.         If IsNumeric(TextBox1.Text) Then
    18.             If TextBox1.Text IsNot Nothing AndAlso CInt(TextBox1.Text) > 0 Then
    19.                 Delay(0.5)
    20.                 PictureBox1.Location = New Point(PictureBox1.Location.X - CInt(TextBox1.Text), PictureBox1.Location.Y)
    21.                 Delay(0.5)
    22.                 PictureBox1.Location = New Point(PictureBox1.Location.X - CInt(TextBox1.Text), PictureBox1.Location.Y)
    23.                 Delay(0.5)
    24.                 PictureBox1.Location = New Point(PictureBox1.Location.X + CInt(TextBox1.Text), PictureBox1.Location.Y)
    25.                 Delay(0.5)
    26.                 PictureBox1.Location = New Point(PictureBox1.Location.X + CInt(TextBox1.Text), PictureBox1.Location.Y)
    27.             End If
    28.         End If
    29.     End Sub
    30. 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
  •  



Featured


Click Here to Expand Forum to Full Width