Controls and Properties / Picture Boxes
Subtitles of the Movie
In this movie I will demonstrate the use of PictureBoxes. Often times you might want to display on the form a picture or icon or some other graphical image. To begin I will find the PictureBox control in the tool box. You simply click like you would any other control and then simply draw the container for the picture box onto the form. Just like any other control, a PictureBox can be renamed, and as you can see the default name for PictureBox is PictureBox 1. I will leave that as the name for the time being until I import an image, so I'll go down to the image property and this is where you actually will need to retrieve the picture file that you want to display onto your form. Click the Ellipses button and then simply select the item that you want to import into your form and then click OK and then you have the image only your form. Now as you can see I have a picture of a water lily and I can resize the PictureBox control to whatever size is appropriate. At this point I will want to rename the picture box to something descriptive of its contents so I will call this Water Lily PictureBox. And there are many things you can do with a PictureBox control. You can actually click on it and calls code just as you would any other control, sometimes you might make the image disappear or reappear. Let me demonstrate at this point, to do so I'll place two buttons onto the form just near the top. One button will be used to make the image appear while the other button will be used to make it disappear. I will begin by renaming the buttons. I will make this, I will call this Visible Button, since this will be the button to make it appear, and I will make this button named Invisible Button. Going back to the Visible Button I will change the text property to read ÒMake visibleÓ so the user will be able to know this button's function. Go to the second button and I will write ÒMake disappear.Ó So now the user is presented with these two choices to make the image appear or disappear. To make these buttons functional, I do need to write some code. Every control can also be made visible and invisible. There is a visible property, if I click on the Water Lily PictureBox control itself, and scroll down to the visible property you will see that by default, it is true. That is, initially the picture will be true. To manipulate this, I simply need to change the visible property at runtime. So, I will begin by double clicking on the Make Visible button which opens up the code window and here I need to know the name of the control which is waterLilyPictureBox.visible is the property I want to affect equals true because this is the visible button. I'll return to the form and double click on the Make Disappear button and I write similar code that says WaterLily.visible again but this time set it equals false. So now when the project is executed and the user clicks on the visible button, this line of code will be executed, that is waterLilyPictureBox.visible equals true. When they click on the invisible button, this line of code will be executed, waterLilyPictureBox.visible equals false. So return to the form and run the project to see if it works. Project is now running, as you can see the image is, automatically appears so if I click the Make Visible button, nothing happens since it already appears, if I click the Make Disappear, as you can see that causes the image to completely disappear, to make it reappear I click the Make Visible button. As programs become more complex we will have more use for PictureBoxes.
Tutorial Information
| Course: | Microsoft Visual Basic 2005 |
| Author: | Arthur Lee |
| SKU: | 33940 |
| ISBN: | 1-935320-10-6 |
| Release Date: | 2008-11-19 |
| Duration: | 7.5 hrs / 97 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 