| Topic: Graphics,Image and Chart Control In this lesson we will consider the construction of the following Graphic Projects:
One can place Graphics on three controls:
The main difference between these three controls is that the ImageBox is specially designed for displaying bitmaps, whereas the other two controls provide drawing methods, which let you design graphics at run time. 1. Project for Graphing any Function: Drag a Picture box, and two command button in the form, size them, caption them and position them as shown in the figure 1. Open the code window of the command button and enter the codes as shown in the figure 1a. Save and run the project. You will get the graph for the function cos(3x)*sin(5x). You can try with different types of functions and see how the scale properties are calculated for each function and the graphs are drawn. A typical output is shown in the figure 2. Private Sub Command1_Click() Function functioneval1(ByVal x As Double) As Double Private Sub Command2_Click() Figure 1a
Figure 2 2. Project for Drawing a Piechart: The Piechart application uses the Circle method to draw pie charts with connected arcs. Because a connected arc is a closed shape, it can also be filled with a pattern or a solid color as specified by the FillStyle and FillColor properties. The program generates 10 random numbers in the range 20 to 100, stores them in the piedata() array, and then calculates the arc that corresponds to each number. Because the total must be a full circle, each element of the piechart() array corresponds to an arc of 2*pi*piedata()/total. Each slice’s starting angle is the ending angle of the previous slice, and its ending angle is the starting angle plus the angle corresponding to the element in the piedata array. Drag two check boxes and three command buttons from the Toolbox, caption them, size them and position them as shown in the figure 3. Open the code window of the command buttons and enter the codes as shown in the figure 4a.. Save and run the application. The run mode window will appear as in the figure 4. Private Sub Command1_Click() Private Sub Command2_Click() Private Sub Command3_Click() Figure 4a
3. Colored Pixels: Pixels are created using the Pset method and they are colored randomly using the QB color function. Drag two command buttons on the form and position them as shown in the figure 5. Open the code window of the command buttons and enter the code as shown in the figure 6a. Save and run the project. You will find the pixels are created in random colors. The output will look as in the figure 6. Private Sub Command1_Click() Private Sub Command2_Click() Figure 6a
4. Project for displaying color gradient: The program shown in the figure 7a is intended to display a gradient of colors in a picture box. The design window consists of one picture box and a command button as shown in the figure 7. On executing this program you will find a color gradient filling the picture box as shown in the figure 8. You can try with different starting and ending colors by changing the RGB values. Private Sub Command1_Click() Function getred(colorval As Long) As Integer Function getgreen(colorval As Long) As Integer Function getblue(colorval As Long) As Integer Figure 7a
Figure 8
|