You can draw and fill boxes using the Line method. The following example draws a box with an upper-left corner at (500, 500) and measuring 1,000 twips on each side:
Line (500, 500)–Step(1000, 0)
Line -Step(0, 1000)
Line -Step(–1000, 0)
Line -Step(0, –1000)
However, Visual Basic provides a much simpler way to draw a box. When you use the B option with the Line method, Visual Basic draws a rectangle, treating the specified points as opposite corners of the rectangle. Thus, you could replace the four statements of the previous example with the following:
Line (500, 500)–Step(1000, 1000), , B
Note that two commas are required before B, to indicate the color argument was skipped. The syntax of the Line method is covered in "Drawing Lines and Shapes" earlier in the chapter.
As long as you do not change the setting of the FillStyle property, the box appears empty. (The box does get filled with the default FillStyle and settings, but FillStyle defaults to 1-Transparent.) You can change the FillStyle property to any of the settings listed in the following table.
Setting | Description |
0 | Solid. Fills in box with the color set for the FillColor property. |
1 | Transparent (the default). Graphical object appears empty, no matter what color is used. |
2 | Horizontal lines. |
3 | Vertical lines. |
4 | Upward diagonal lines. |
5 | Downward diagonal lines. |
6 | Crosshatch. |
7 | Diagonal crosshatch. |
Thus, setting FillStyle to 0 fills the box solidly with the color set for the FillColor property.
Another way to fill the box is to specify F after the B. (Note that F cannot be used without B.) When you use the F option, the Line method ignores FillColor and FillStyle. The box is always filled solid when you use the F option. The following statement fills the box with a solid pattern, using the ForeColor property:
Line (500, 500)–Step(1000, 1000), , BF
The result is shown in Figure 12.15.
Figure 12.15 A box filled with a solid pattern