Use ScrollBar as input device
Scroll bars are usually used with TextBox or windows, but sometimes they can also be used as input devices. Because the ScrollBar control indicates the current position proportionally, it can be used alone to control program input, such as controlling sound volume or adjusting picture color. The HScrollBar (horizontal) and VScrollBar (vertical) controls are independent and have their own set of events, properties, and methods. The ScrollBar control is different from the internal ScrollBar attached to a TextBox, ListBox, ComboBox, or MDI form. (TextBox and MDI forms have the ScrollBars property, which can add or remove ScrollBars attached to the control.)
The Windows interface prompt now supports the Slider control as an input device instead of the ScrollBar. For an example of the Slider control, see the Windows 95 Control Panel. The Professional and Enterprise editions of Visual Basic include a Windows95-style Slider control.
For more information about the ScrollBar control, see Chapter 7, "Using Visual Basic's Standard Controls."
Controls for displaying pictures and graphics
Because Windows is a graphical user interface, the method of displaying graphic images on the application interface is very important. VisualBasic contains four controls to simplify graphics-related operations, they are the PictureBox control, Image control, Shape control and Line control.
Image, Shape, and Line controls are sometimes called lightweight graphics controls. They require fewer system resources, therefore display faster than PictureBox controls and contain a subset of the properties, methods, and events available in PictureBox. Each control serves a specific purpose.
Using the PictureBox control
The main function of the PictureBox control is to display pictures for users. The actual displayed picture is determined by the Picture property. The Picture property contains the file name (and optional path name) of the picture being displayed.
Note that the form object also has a Picture property. By setting this property, the picture can be displayed directly on the form background.
To display or replace a picture at runtime, use the function LoadPicture to set the Picture property. Provide a picture file name and optional path name, and the LoadPicture function handles the details of loading and displaying the picture.
picMain.Picture=LoadPicture(VANGOGH.BMP)
The PictureBox control has the AutoSize property. When this property is set to True, the PictureBox can automatically adjust the size to match the displayed picture. If you want to use a PictureBox with the AutoSize property set to True, you need to be particularly careful when designing the form. The picture will resize without taking into account other controls on the form, which can lead to unintended consequences, such as overwriting other controls. When designing, you should check whether this phenomenon occurs by loading each image.
Use PictureBox as container
The Picturebox control can also be used as a container for other controls. Like the Frame control, you can add other controls on top of the PictureBox control. These controls move as the PictureBox moves, and their Top and Left properties are relative to the PictureBox and have nothing to do with the form.
A common use of PictureBox containers is ToolBar or StatusBar. Image controls can be placed in these containers as buttons or add Labels to display status information. Set the Align property to Top, Bottom, Left, or Right, and the PictureBox will stick to the edge of the form. Figure 3.16 shows a PictureBox with the Align property set to Bottom. It contains two Label controls that can be used to display status information.
Other uses of PictureBox
The PictureBox control has several ways to make the PictureBox available for other purposes. For example: Think of the PictureBox as an empty canvas on which you can draw or print, or display text, graphics, or even simple animations.
The PRint method allows text to be output to the PictureBox control as if it were output to a printer. There are several font properties that control the characteristics of text input by the Print method; the Cls method clears the output.
Circle, Line, Point and Pset methods can be used to draw graphics in PictureBox. Properties such as DrawWidth, FillColor, and FillStyle allow customizing the appearance of graphics.
Use the PaintPicture method to move the Image within the picture control and move between several different Images.
Quick changes can create animations.
For more information about the PictureBox control, see Chapter 7, "Using Visual Basic's Standard Controls."
Lightweight graphics control
Image, Shape, and Line controls are all considered lightweight graphics controls, that is, they only support a subset of PictureBox's properties, methods, and events. Therefore, they require fewer system resources and load faster than PictureBox controls.
Use Image control instead of PictureBox
The Image control is similar to the PictureBox control, but it is only used to display pictures. It cannot be used as a container for other controls, nor does it support the advanced methods of PictureBox. Pictures are loaded into an Image control the same way they are loaded into a PictureBox. When designing, set the Picture property to the file name and path, and when running, use the Loadpicture function.
The resizing behavior of the Image control is different from that of the PictureBox. It has Stretch property and PictureBox has AutoSize property. Setting the AutoSize property to True will cause the PictureBox to resize according to the image, and setting it to False will cause the image to be clipped (only part of the image is visible). When the Stretch property is set to False (the default value), the Image control can be resized according to the picture. Setting the Stretch property to True will resize the image according to the size of the Image control.
size of the piece, which may distort the picture.
For more information about the Image control, see Chapter 7, "Using Visual Basic's Standard Controls."
Create your own button using Image control
The Image control also recognizes the Click event, so it can be used anywhere a CommandButton is used. This method makes it easy to create buttons with pictures in place of titles. A ToolBar can be established in the application by grouping several Image controls and placing them horizontally at the top of the screen (usually in a PictureBox).
For example, for the Image control given in the TestButtons example, the user can select it just like the CommandButton. When the form is first displayed, the control displays one of three traffic icons from Visual Basic's icon library. Each time you click the Image control, a different icon is displayed (for a working version of this example, see Button.frm in the Controls.vbp sample application).
If you look at the form while designing, you'll see that it actually contains all three icons stacked together. Change the Visible property of the top Image control to False and the next image (if its Visible property is True) will be displayed on top.
Figure 3.17 shows a traffic icon Image control (Trffc10a.ico).
To create a border around the Image control, set the BorderStyle property to 1—a fixed single border.
Note that unlike the CommandButton, when you click the Image control, it does not display the action of being pressed. That is to say, unless the bitmap is changed in the MouseDown event, the "button" being pressed is invisible to the user.
For more information about displaying graphic images in the Image control, see Chapter 7, "Using Visual Basic's Standard Controls."
Use Shape control and Line control
Shape and Line controls can be used to draw graphic elements on the surface of the form. These controls do not support any events and are only used for surface decoration.
There are several properties that control the appearance of a Shape control. By setting the Shape property, the Shape control can be displayed as a rectangle, square, oval, rounded rectangle, or rounded square. Setting the BorderColor and FillColor properties can change the color, and the BorderStyle, BorderWidth, FillStyle, and DrawMode properties control how to draw. The Line control is similar to the Shape control, but is only used for drawing lines.
For additional information about the Shape and Line controls, see Chapter 7, "Using Visual Basic's Standard Controls."
Images app
The form shown in Figure 3.18 uses four Image controls, a Shape control, a PictureBox control and a CommandButton control. When the user selects a playing card symbol, the Shape control highlights the symbol and displays a corresponding description in the PictureBox. For a working version of this example, see Images.frm in the Controls.vbp sample application.
The following table lists the property settings for objects in the application.
->