HOWTO: VB3: Adjust FontSize at Run-time for Diff. Video DriversLast reviewed: September 29, 1997Article ID: Q106164 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SUMMARYText on controls and labels may have a different size or appearance at run time depending on the video device and driver. For example, many video drivers have a large-fonts option and a small-fonts option. This article describes how to adjust text at run-time automatically to fit the design- time label size, independent of the video driver.
MORE INFORMATIONPredicting how fonts will appear on different display devices is not easy. However, you can calibrate the appropriate FontSize to use at run time by using the following example. This example adjusts the form's FontSize so that a particular label caption fits best inside its Width. The label's Width can be set at design time to adjust how big the fonts ought to appear at run time. This example assumes a True Type FontName setting, which can be set to almost any size needed.
Step-by-Step Example
You can also have the program size label controls depending on the Screen.Height and Screen.Width properties at run time. Once you determine the correct size of the label, size the text inside the label.
Example of How Fonts May Differ on Different HardwareYou can call Windows API functions to obtain the enumerated FontSize list. This is useful to know for fixed, non-TrueType fonts. Visual Basic also offers font properties (Fonts, FontName, FontSize, and FontCount) to determine font information. The enumerated FontSize list for non-TrueType fonts may vary from one screen resolution to another. This can happen because the number of logical pixels per inch can vary between resolutions. This means that the number of points per pixel can also vary. The point size of a font is adjusted to the nearest pixel. The point size on a screen is based on logical inches. Logical inches are somewhat arbitrary because Windows has no way of really knowing how big a pixel is on your screen. For example, you could be hooked up to a projection TV or a tiny monitor. Usually the logical inch is overly large; tiny text is often difficult to read on a video display. Because the point size is based on the logical pixels per inch of a device, not all point sizes can be represented. For example, on a standard VGA, Windows will tell you that the device has 96 pixels per logical inch (according to the Windows API GetDeviceCaps(hDC, LOGPIXELSY) function). A 96-pixel tall glyph is 72 points because each point is about 1/72 of an inch. This means each pixel is 72/96 point or 0.75 point per pixel. The system could theoretically represent fonts of the following heights:
1 pixel = 0.75 point 2 pixels = 1.50 point 3 pixels = 2.25 point 4 pixels = 3.00 pointRounding errors are unavoidable in this scheme. Even if the device displayed exactly 96 dots per inch (DPI), it could not represent a font that was exactly 2 points. The closest it could come would be 2.25 points. Usually, this small difference is not noticeable. However, if two screen drivers have different logical pixels-per-inch, you might see different point sizes in the enumerated list in Windows. Keywords : PrgCtrlsStd vbwin GnrlVb kbprg kbfasttip Technology : kbvba Version : WINDOWS:3.00 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |