News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Animation In Visual Basic - Part 2

Started by VelMurugan, Jul 16, 2008, 06:27 PM

Previous topic - Next topic

VelMurugan

Animation In VB

Another simple way to simulate animation in VB6 is by using the Left and Top properties of an object. Image.Left give the distance of the image in twips from the left border of the screen, and Image.Top give the distance of the image in twips from the top border of the screen, where 1 twip is equivalent to 1/1440 inch. Using a statement such as Image.Left-100 will move the image 100 twips to the left, Image.Left+100 will move the image 100 twip away from the left(or 100 twips to the right), Image.Top-100 will move the image 100 twips to the top and Image.Top+100 will move the image 100 twips away from the top border (or 100 twips down).Below is a program that can move an object up, down. left, and right every time you click on a relevant command button.



The Codes

        Private Sub Command1_Click()
        Image1.Top = Image1.Top + 100
        End Sub

        Private Sub Command2_Click()
        Image1.Top = Image1.Top - 100
        End Sub

        Private Sub Command3_Click()
        Image1.Left = Image1.Left + 100
        End Sub


        Private Sub Command4_Click()
        Image1.Left = Image1.Left - 100
        End Sub

         
The fourth example let user magnify and diminish an object by changing the height and width properties of an object. It is quite similar to the previous example. The statements  Image1.Height = Image1.Height + 100  and Image1.Width = Image1.Width + 100 will increase the height and the width of an object by 100 twips each time a user click on the relevant command button. On the other hand, The statements  Image1.Height = Image1.Height - 100  and Image1.Width = Image1.Width -100 will decrease the height and the width of an object by 100 twips each time a user click on the relevant command button

   

The Codes

Private Sub Command1_Click()
Image1.Height = Image1.Height + 100
Image1.Width = Image1.Width + 100
End Sub


Private Sub Command2_Click()

Image1.Height = Image1.Height - 100
Image1.Width = Image1.Width - 100

End Sub


You can try to combine both programs above and make an object move and increase or decrease in size each time a user click a command button.