![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Drawing In Picture Boxes And On FormsSo far, we have seen how to display and manipulate existing images in Picture Boxes and on forms. What if you want to create an image from scratch? Visual Basic has several statements that let you draw just about anything imaginable. When you draw in a Picture Box or on a form, a current position always marks the location where the most recent drawing operation finished. The current position is defined by the objects CurrentX and CurrentY properties. With no draw operations or if the objects graphics have been erased with the Cls methodthese properties both default to zero. The Line MethodWhen you want to draw lines and rectangles on Form, Picture Box, and Printer objects, use the Line method object.Line (X1, Y1)-(X2, Y2), color, mode The arguments are as follows:
You can specify color in two ways. The RGB function lets you specify a color in terms of the relative intensities of the red, green, and blue components. Heres the syntax: RGB(red, green, blue) Each of the three arguments is a number in the range 0 through 255, specifying the relative intensity of the color. For example, the statement Form1.Line (0,0)-(500,500), RGB(0,0,255), BF will draw a rectangle that is completely blueboth its border and interior. You can also specify color with the QBColor function. Its syntax is: QBColor(color) Here, the color argument is a number in the range 0 through 15, which corresponds to one of the colors in Table 12.6. The QBColor function gives you easy access to the 16 colors available in the old Quick Basic programming language.
Color Mixing DemonstrationThe main purpose of this demonstration program is to show you how the Line method and the RGB function work, but youll also gain some experience in using control arrays and Scroll Bar controls. The programs single form contains a Scroll Bar and Text Box for each of the three primary colors. The Text Boxes display numerical valuesfrom 0 to 255that you change by using the Scroll Bar. The values, of course, represent the color intensity. A rectangle displaying the selected color is drawn on the form whenever the user changes one of the Scroll Bar values. The final program is shown in Figure 12.11. To create the program, start a new project and place a control array of three VScrollBar controls and another array of three Text Box controls on the form. Add three Label controls with the Caption properties set to Red, Green, and Blue, respectively. Position the controls on the form, as shown in Figure 12.11. Be sure that the Scroll Bar and Text Box with Index 0 are under the Red label, that the Scroll Bar and Text Box with Index 1 are under the Green label, and that the Scroll Bar and Text Box with Index 2 are under the Blue label. Change the forms Caption property to Color Tester and save both the project and the form with the name COLORS.
Now we can turn to the code, shown in Listing 12.9. Initialization steps are performed in the Form_Load event procedure, as usual. This consists mainly of setting the Scroll Bar properties. Because the three Scroll Bars are all part of a control array, we can use a For...Next loop to loop through them (another advantage of control arrays). The Scroll Bars Value property returns its current setting. You can set several properties to customize each Scroll Bar to suit your current needs:
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |