How to Create Animation in Visual Basic

In this tutorial, I will teach you how to create animation that has image Magnifying and controls to the left, right, up, and down in Visual Basic. Here is the example for magnifying and let user magnify and diminish an object by changing the height and width properties of an object. 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

Sample Code

Magnifying Command Script
  1. Private Sub Command1_Click()
  2. Image1.Height = Image1.Height + 100
  3. Image1.Width = Image1.Width + 100
  4. End Sub
  5.  
  6. Private Sub Command2_Click()
  7.  
  8. Image1.Height = Image1.Height - 100
  9. Image1.Width = Image1.Width - 100
  10.  
  11. End Sub

Sample Image

Result And for the controls of animation here is the another simple way to simulate animation 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.

Sample Code

  1. Private Sub Command1_Click()
  2. Image1.Top = Image1.Top + 100
  3. End Sub
  4.  
  5. Private Sub Command2_Click()
  6. Image1.Top = Image1.Top - 100
  7. End Sub
  8.  
  9. Private Sub Command3_Click()
  10. Image1.Left = Image1.Left + 100
  11. End Sub Private Sub Command4_Click()
  12. Image1.Left = Image1.Left - 100
  13. End Sub

Sample Image

Result For more tutorials just visit this website @www.sourcecodester.com and don't forget to Like and Share. Enjoy Coding.

Add new comment