130 likes | 166 Views
VB Graphics Controls & Timer Control. Default Controls. Graphics File Formats used with VB. Using Images. At design time: Select a image thru the Picture property (form, Picture box or Image Box) At Runtime: Form1.Picture = LoadPicture(“C:MYPIC.BMP”)
E N D
Using Images • At design time: Select a image thru the Picture property (form, Picture box or Image Box) • At Runtime: Form1.Picture = LoadPicture(“C:\MYPIC.BMP”) Image1.Picture = LoadPicture(“D:\PAMELA.JPG”) Picture1.Picture = image1.Picture Picture1.Picture = LoadPicture(“”) • Passing an empty string to the LoadPicture function clears the current picture.
Using Images with Forms • At design time: Select a form background image thru the Picture property • At Runtime: Form1.Picture = LoadPicture(“C:\MYPIC.BMP”) • picture that is placed directly on a form. If you want the picture to be a different size, you need to resize the original graphic file using a graphics utility.
Using Images with Forms • Placing the picture directly on the form have several drawbacks: • You cannot hide the picture; it can only be loaded or unloaded. • You cannot control the placement of the picture on the form. • You can place only one picture at a time on the form. • You cannot resize the picture. It’s placed on the form in its original (saved) size. • You can overcome these drawbacks by using the Picture or Image control.
Image Control • Provides a frame for the picture, allowing you to position it anywhere on the form. • Pictures can be resized. • Stretch property: • False (the default): the Image control is automatically resized to fit the picture you assign to it. • True: the picture is automatically resized so that the entire picture fits within the current boundaries of the Image control.
PictureBox Control • Although the PictureBox control uses more system resources than the Image control, it has some added features: • Can be used as a container for other controls • Drawing methods (for example, Line and Print) can be used to draw on the picture box • PictureBox does not allow resizing of the picture • Setting AutoSize property to True cause the PictureBox control to resize itself to fit the current picture.
The Timer Control • Executes code (in its Timer event) when the interval is complete. • Counts down repeatedly, as long as the Enabled property is set to True. • Designed to work with very small amounts of time; the maximum setting is just a little longer than a minute. • Uses: scheduling and performing repeated operations.
Setting Up the Timer • First draw it on the form, it does not show up at all while your program is running. • Place code in the Timer event and then set the following properties, either at designtime or runtime: • Set the Interval property. • Set the Enabled property to True. The Interval property can be set to any value between zero and 65,535.
The Timer Control • The Enabled property acts like a switch that turns your timer on and off. If the Timer control is enabled, the code in the Timer event is executed at the end of the time specified in the Interval property. • The Interval property can be set to any value between zero (disables the Timer control) and 65,535 milliseconds. • 10 seconds = 10,000 milliseconds.
Creating a Simple Animation Following is an example of using the timer control for a simple animation. Set the Interval property to 200 and the Enabled property to True.