|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Drawing Thicker, Dotted, And Dashed LinesUsing the line control, you can select a line style with the BorderStyle property. Here are the possible values for the line controls BorderStyle property:
To set a lines width, you use the BorderWidth property (the default value is 1). It seems a little odd to call the lines style BorderStyle and its width BorderWidthafter all, what is the line a border to? However, those properties are named that way to be consistent with the shape control.
Drawing A Line Without The IDE GridWhen you draw lines in the Visual Basic Integrated Development Environment (IDE), those lines fall along the dotted grid you can see in forms. That grid can help in aligning controls and lines, but there are times when you want finer control. To turn off the automatic alignment of controls to the grid as you draw them, follow these steps:
Thats it. Now youre free to draw controls as you want them and where you want them, without having your controls boundaries fall on a grid line.
Changing A Line Control At RuntimeYou can move Visual Basic controls at runtimewhy not line controls? You cant use the Move method to move a line control at runtime, but you can move or resize it by altering its X1, X2, Y1, and Y2 properties. Lets see an example. In this case, weve added four random line controls to a form in a control array, LineControl(0) to LineControl(3). When the user clicks a command button, Command1, we loop over all four lines and arrange them horizontally. Heres what the code looks like (the measurements are in the Visual Basic default, twips, or 1/1440s of an inch):
Private Sub Command1_Click()
Dim intLoopIndex As Integer
For intLoopIndex = 0 To 3
LineControl(intLoopIndex).X1 = 1000
LineControl(intLoopIndex).X2 = 3500
LineControl(intLoopIndex).Y1 = 1000 + 100 * intLoopIndex
LineControl(intLoopIndex).Y2 = LineControl(intLoopIndex).Y1
Next intLoopIndex
End Sub
The result of this code appears in Figure 14.14. Now were moving lines around at runtime.
Using Form Methods To Draw LinesWeve seen how to draw lines with the line controlbut you can use a form method, the Line method, to draw lines directly. The Line method can be an important part of graphic design (especially if you want to draw lines in a loop and dont want to create a dozen or more line controls), and because were covering that topic in this chapter, well look at the line control here. Heres how you use the Line method: [Form.]Line [(x1, y1)]&45;(x2, y2)[, color] Lets see an example. Here, well just draw four lines with the Line method when a form first loads. As with other graphic methods, to use this method in the Form_Load() handler, you must set the forms AutoRedraw property to True. Heres the code we add to the Load event, making use of the Line method:
Private Sub Form_Load()
Dim intLoopIndex As Integer
For intLoopIndex = 0 To 3
Line (1000, 1000 + 400 * intLoopIndex)-(3500, 1000 + 400 _
* intLoopIndex)
Next intLoopIndex
End Sub
The result of the preceding code appears in Figure 14.15you can see the four lines weve drawn there.
Using Form Methods To Draw CirclesWeve seen that you can use the shape control to draw circles, but there is also a form method to do the same thing: the Circle method. Heres how you use the Circle method: [Form.]Circle (x, y), radius[, color] For example, heres how we draw a few circles in a form using the Circle method (note that as with all graphics methods used in the Form_Load() event handler, you must set the forms AutoRedraw property to True here):
Private Sub Form_Load()
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 4
Circle (2300, 500 + 400 * intLoopIndex), 400 * intLoopIndex
Next intLoopIndex
End Sub
Running this code yields the result you see in Figure 14.16. Now were drawing circles using the forms Circle method.
|
|
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. |