Programming: VB Programming Tutorial #4
Posted: Sat Feb 12, 2005 6:11 pm
Whoa! Its been a long time since I wrtoe another tut. Expect more to come shortly after this.
In this tut, you will learn to make objects move around the screen using Command buttons.
Start off by making a new project. Standard Exe
Now that you have the form made. Change the name to
Frm1
Your welcome to change it to anyname you want. Also, feel free to change the caption
Now, go over to shapes in your toolbox. And drag out a shape onto the form. You cannot select the shape first. So it automaticly gives you a square
Now that you have that done. Rename the shape to
Shp1
' Shape = Shp
And go down to Shape under Properties. Change the shape to Circle
Now its time to make the command buttons. Arrange them to line up like the arrows of your keyboard.(See pic)
Now its time to name them
The command button for up's name should be
cmdup
And the command button for down's is
cmddown
And so on.......
Now that the UI is set up. Its time for some code. The code is pretty straightfoward
Open up the code for cmdup. Type
shp1.top=shp1.top-100
Now to break it down. Shp1.top means. Shp 1's top properties.
Shp1.top=Shp1.top-100 means find shp1.top's current position, and minus that by 100 pixels. Normaly + means to go up, and - to go down. But VB is different. 0,0 on the form is at the top left corner. Not the bottom left corner like a graph.
Now open the code for cmddown. Use
shp1.top=shp1.top+100
Properties in vb are only Top, and left. There is no right, or down
Now open the code for cmdleft. Use
shp1.left=shp1.left-100
Again, same as the top
Again, open cmdright's code. And type
shp1.left=shp1.left+100
Now open the code for cmdexit. Use
Unload Me
Thats to shut the program down
Wthe program runs. Click on the command buttons to move the shaps. You have to click them multiple times to get it to move far. But you could always increase to number from 100 +
Well, sry for the delay. I get busy sometimes. Expect more tuts very soon. For now
Enjoy!
In this tut, you will learn to make objects move around the screen using Command buttons.
Start off by making a new project. Standard Exe
Now that you have the form made. Change the name to
Frm1
Your welcome to change it to anyname you want. Also, feel free to change the caption
Now, go over to shapes in your toolbox. And drag out a shape onto the form. You cannot select the shape first. So it automaticly gives you a square
Now that you have that done. Rename the shape to
Shp1
' Shape = Shp
And go down to Shape under Properties. Change the shape to Circle
Now its time to make the command buttons. Arrange them to line up like the arrows of your keyboard.(See pic)
Now its time to name them
The command button for up's name should be
cmdup
And the command button for down's is
cmddown
And so on.......
Now that the UI is set up. Its time for some code. The code is pretty straightfoward
Open up the code for cmdup. Type
shp1.top=shp1.top-100
Now to break it down. Shp1.top means. Shp 1's top properties.
Shp1.top=Shp1.top-100 means find shp1.top's current position, and minus that by 100 pixels. Normaly + means to go up, and - to go down. But VB is different. 0,0 on the form is at the top left corner. Not the bottom left corner like a graph.
Now open the code for cmddown. Use
shp1.top=shp1.top+100
Properties in vb are only Top, and left. There is no right, or down
Now open the code for cmdleft. Use
shp1.left=shp1.left-100
Again, same as the top
Again, open cmdright's code. And type
shp1.left=shp1.left+100
Now open the code for cmdexit. Use
Unload Me
Thats to shut the program down
Wthe program runs. Click on the command buttons to move the shaps. You have to click them multiple times to get it to move far. But you could always increase to number from 100 +
Well, sry for the delay. I get busy sometimes. Expect more tuts very soon. For now
Enjoy!