• No results found

Default Font

In document VFP Report Writer (Page 134-139)

You may have wondered why the Report Designer chooses to use the Courier New, Regular, 10 font when objects are first added to the report. The answer is because that’s the default font. However, you can change the default font of any given report by selecting Report | Default Font… from the main VFP Menu bar. This invokes the same Font dialog shown in Figure 4.

Once you change the default font of a report, any newly added objects—to this report only—use the new default font. All previously added objects, and all previously defined reports, remain unaffected by the change. If you wish to change the font of existing objects, use the method just described in the section titled “Font.”

The default font is saved with the report, so each time you edit a particular report with the VFP Report Designer, the same default font remains in effect for the given report.

Unfortunately, there’s no way to change what the default setting is for Default Font. Each new report you create always starts out with a default font of Courier New, Regular, 10.

In FoxPro 2.x the default font is accessed by selecting Report | Page Layout… from the FoxPro system menu bar. Then select the Font…

button from the Page Layout dialog.

Color

With today’s wide variety of color printers, our users often want a lot of color on their reports.

But even if you’re limited to just a black and white printer, don’t think the color options don’t apply to you. The color options are still important because often the user wants a gray box here or reverse text there to make things stand out.

The coloring of objects is broken out into two different colors, the foreground color and the background color. The foreground color determines what color is used for the text of Label and Field objects and the lines used to draw Line, Rectangle, and Rounded Rectangle objects.

The background color determines what color is used to fill the inside of a Rectangle or Rounded Rectangle object as well as the background of a Label or Field object.

In FoxPro 2.x, you only have access to 16 basic colors and are not allowed to describe any custom colors as you can with Visual FoxPro.

Basic colors

To change the foreground color of an object, select the object. Then select Format |

Foreground Color… from the main VFP Menu bar. This displays the Color dialog shown in Figure 5 (although it’s just not the same when printed on a black and white page in a book).

You may select any of the basic 48 colors from this dialog and then select the OK button to return to the Report Designer with the foreground color of the selected object changed.

Figure 5. Use the Color dialog to choose a wide variety of standard colors.

You may change the background color of an object in much the same manner. Select the object, and then choose Format | Background Color… from the main VFP Menu bar. This displays the same Color dialog shown in Figure 5, from which you can select a color for the background of the selected object.

Custom colors

Besides the 48 basic colors, you may also define custom colors. To expanded the Color dialog with the custom options, select the Define Custom Colors >> button from the Color dialog. As shown in Figure 6, the left side of the dialog is still the same. However, the right side of the dialog is filled with everything necessary to create custom colors.

Figure 6. Use the expanded Color dialog to define very specific colors for objects.

The large rainbow-filled square on the right-hand side of the dialog is a matrix of all the possible colors. Moving across the X-axis of the matrix changes the Hue of the current custom color. Moving up or down the Y-axis of the matrix changes the Saturation level of the current custom color. To the right of the matrix is a narrow vertical bar. Moving within this bar changes the luminous value of the current custom color. As you move within either the matrix or luminous bar, the current color is displayed in the Color|Solid box underneath the matrix.

All these terms (hue, saturation, and luminous) are probably foreign to you. In FoxPro, we refer to colors by the Red/Green/Blue value, or RGB value. This is just another way to

represent a color. The Color dialog shows both the HSL value and the RGB value of the current color in text boxes next to the Color|Solid box. You may tweak any of these values and the newly identified color appears in the Color|Solid box.

Once the exact color you’re looking for is defined, select the Add to Custom Colors button on the expanded Color dialog. This adds the current color to one of the 16 Custom colors boxes. If all the custom color boxes are currently filled, the Report Designer overwrites the first custom color, then the second custom color, and so on. When you have all the necessary custom colors defined, select the OK button to apply the currently selected color to the selected object or select the Cancel button to return to the Report Designer without applying a new color to the selected object.

Now that you have custom colors defined, each time you invoke the Color dialog, those custom colors remain at the bottom of the dialog so you can apply them to objects. These custom colors are stored with the report. The next time you edit the report, the same custom colors appear.

Even though there are only 16 positions on the Color dialog for custom colors, it doesn’t mean you can only use 16 custom colors on the report. Once the color of an object is changed, that information is permanently saved with that object. It doesn’t rely on a custom color set up in the Color dialog. You can define a bunch of objects using the current custom colors. Then you can change the colors in the Custom colors section of the Color dialog and apply the new colors to a bunch of different objects. Changing the colors in the Custom colors section of the Color dialog does not affect any of the objects that are already defined.

The Color Palette toolbar

You can also change the foreground and background color of objects using the Color Palette toolbar shown in Figure 7. You can display the Color Palette toolbar with one of three methods. The first method is to select View | Color Palette Toolbar from the main VFP Menu bar. The second method is to select the Color Palette Toolbar button from the Report Designer toolbar. The third method is to right-click on an unused portion of any docked toolbar and then select Color Palette.

Figure 7. Use the Color Palette toolbar to change the foreground and background color of objects.

Learning to use this toolbar is somewhat tricky and confuses a lot of developers. The first two buttons, Foreground Color and Background Color, are used to toggle the foreground and background modes, respectively. When a foreground or background mode is on, its associated button is sunken. The next 16 buttons are used to choose a specific color. The last button, Other Colors, is used to invoke the Color dialog shown in Figure 5.

To change the foreground color of an object using the Color Palette toolbar, follow these steps:

1. If the Foreground Color button isn’t sunken, select it so it is.

2. If the Background Color button is sunken, select it so it isn’t.

3. Select the object you want to change.

4. Select one of the 16 colors from the Color Palette toolbar.

‡

To change the background color of an object using the Color Palette toolbar, follow these steps:

1. If the Foreground Color button is sunken, select it so it isn’t.

2. If the Background Color button isn’t sunken, select it so it is.

3. Select the object you want to change.

4. Select one of the 16 colors from the Color Palette toolbar.

It’s really quite simple once you get the hang of it. What usually throws developers is that they try to select the object and color first, then select the Foreground Color or Background Color button, which is completely opposite of what you need to do.

Note: When you change the background color of a Field object, you also have to change the Mode (discussed later in this chapter) to opaque or the color doesn’t show up on the report even though you see it in the Report Designer.

You can also toggle both the Foreground Color and Background Color buttons on and select an object and a color to change both the foreground and background color at the same time. I know what you’re thinking: “That’s stupid. If the foreground and background color is the same, how would I see the text?” While that statement is true for text, you haven’t thought about rectangles. The foreground color of a rectangle is used to draw the line around the outside of the rectangle. The background color of a rectangle is used to fill in the rectangle. So when you don’t want a border around the rectangle, you can make the foreground color the same as the background color.

Color tricks

There are two tricks I’d like to mention that have to do with color. The first trick involves gray boxes and the second trick involves dynamically changing the color of an object.

Gray boxes

When designing a report that requires light gray boxes, you can use yellow boxes as long as the report is only printed on a black and white printer. When yellow is converted to black and white, it comes out as a lighter shade of gray than the standard light gray color you can select with the Color dialog. When your users need to fax reports, the lighter shade of gray faxes much better than the regular gray.

Dynamic color

It’s not possible to truly change the color of a Report object dynamically. However, you can create the appearance by using Print When logic. For example, say you want to print a dollar amount that is black when it’s positive or red when it’s negative. Start by adding two Field objects to the report with the same expressions (MyTable.DollarAmt). Next, change the color of one of the objects to red and leave the other object black. Now change the Print When expression of the black object to MyTable.DollarAmt >= 0 and change the Print When expression of the red object to MyTable.DollarAmt < 0. For the final step, place one object

‡

directly on top of the other object, making sure they are aligned perfectly with each other.

When the report prints, either the red dollar amount prints or the black dollar amount prints, but not both of them.

In document VFP Report Writer (Page 134-139)