Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How to move object on window form.

Author: DevASP
Download Source Code : 585_img

This article is about how you can move an object on window form using the timer control.


Steps you will do.



Start VS and create a new window application.


Place two timer controls on the form and set their following properties.



Enabled = False

Interval = 100

Set the above properties for both timer controls.


Drop a picture box control on the form and set its following properties.



Name = pbox1

SizeMode = StretchImage

Image = image file that you want to move over the form


Now open the code window and write the following code.


Declare a global variable as below.


Dim a As Integer

 Write the following code in the Tick event of the first timer control.


        a = 0

          If pbox1.Left < 300 Then 

           pbox1.Left = pbox1.Left + 5


            a = a + 150

            pbox1.Top = a

            Timer1.Enabled = False

            Timer2.Enabled = True

        End If



Now write the following code in the Tick event of the second timer control.



   If pbox1.Left > 0 Then

            pbox1.Left = pbox1.Left - 5


            pbox1.Top = 0

            Timer2.Enabled = False

            Timer1.Enabled = True

        End If


Run your application you will see that the object you specify will move from left to right at the top of window form and then from right to left at the bottom of the window form.











Article Comments

Posted on 8/24/2006 3:24:19 AM by saji

i will use you code to develope a simple game using a sqaure object moving up and down ,left to right by using the arrow keys on the keyboard.pls send me more tricks,thanks.

Posted on 1/5/2007 12:25:10 PM by Mmeti usoh

Add Article Comment:
Name :
Email Address :
Comments :
<< How we can Drag & Drop the objects on Web Form. (Image Drag & Drop)

Disclaimer - Privacy
© 2002-2017