How do you determine the screen font size?
Author |
Message |
Dan #1 / 7
|
 How do you determine the screen font size?
I've been through the MSDN as well as Microsoft's knowledge base and not found this yet. I need a way of determining what the user has sent the Windows display font size to (from the Display Properties dialog, Appearance tab, Font size - normal, large, extra large). The reason is that it makes a difference in my form's height property depending on the size of the font in the caption. This affects how I am moving around controls on the form when the user resizes it (move button to coordinate x based on form.height). ' In case I'm not being clear, here is an example to demonstrate the problem: Create a new project with one form. Set Form1's height to 3600 Add a command button with a height of 495 and set it's top to 2640 In Form1's resize event add the following line of code: Command1.Top = Me.Height - 960 Now run it. If your screen font size (set in the Windows Display Properties dialog) is set to "Normal" then as you resize the form the command button remains right on bottom of your form. But if you set the screen font size to "Large Fonts" or "Extra Large Fonts" then the button's bottom sinks slightly off the form. So my question is, how can I make this sample above smart enough to account for the system's display font size? My example above was put together under Windows XP so if the behavior differs from my description let me know... Thanks! Dan
(take out "TheTrash" to respond via email)
|
Sat, 11 Sep 2004 04:54:53 GMT |
|
 |
Randy Birc #2 / 7
|
 How do you determine the screen font size?
http://www.mvps.org/vbnet/code/screen/screenfont.htm Basically, if logPixels = 96, the user has small fonts. If = 72, the user has large fonts. If <> those values, the user has a custom setting as reflected in the logPix variable. -- Randy Birch MVP Visual Basic http://www.mvps.org/vbnet/ Please respond only to the newsgroups so all can benefit. *** If you call the Sleep API in Bill's latest, will it have .NET dreams? ***
Quote: > I've been through the MSDN as well as Microsoft's knowledge base and not > found this yet. I need a way of determining what the user has sent the > Windows display font size to (from the Display Properties dialog, > Appearance tab, Font size - normal, large, extra large). The reason is that > it makes a difference in my form's height property depending on the size of > the font in the caption. This affects how I am moving around controls on > the form when the user resizes it (move button to coordinate x based on > form.height). ' > In case I'm not being clear, here is an example to demonstrate the problem: > Create a new project with one form. Set Form1's height to 3600 > Add a command button with a height of 495 and set it's top to 2640 > In Form1's resize event add the following line of code: > Command1.Top = Me.Height - 960 > Now run it. If your screen font size (set in the Windows Display Properties > dialog) is set to "Normal" then as you resize the form the command button > remains right on bottom of your form. But if you set the screen font size > to "Large Fonts" or "Extra Large Fonts" then the button's bottom sinks > slightly off the form. > So my question is, how can I make this sample above smart enough to account > for the system's display font size? My example above was put together under > Windows XP so if the behavior differs from my description let me know... > Thanks! > Dan
> (take out "TheTrash" to respond via email)
|
Sat, 11 Sep 2004 05:33:48 GMT |
|
 |
Dan #3 / 7
|
 How do you determine the screen font size?
Randy, Doesn't work on XP (I don't know about other platforms). In the function logPixels always = 96 regardless of what the display font is set to... Dan -- http://www.Auction-Sentry.com
Quote: > http://www.mvps.org/vbnet/code/screen/screenfont.htm > Basically, if logPixels = 96, the user has small fonts. If = 72, the user > has large fonts. If <> those values, the user has a custom setting as > reflected in the logPix variable. > -- > Randy Birch > MVP Visual Basic > http://www.mvps.org/vbnet/ > Please respond only to the newsgroups so all can benefit. > *** If you call the Sleep API in Bill's latest, will it have .NET dreams? > ***
> > I've been through the MSDN as well as Microsoft's knowledge base and not > > found this yet. I need a way of determining what the user has sent the > > Windows display font size to (from the Display Properties dialog, > > Appearance tab, Font size - normal, large, extra large). The reason is > that > > it makes a difference in my form's height property depending on the size > of > > the font in the caption. This affects how I am moving around controls on > > the form when the user resizes it (move button to coordinate x based on > > form.height). ' > > In case I'm not being clear, here is an example to demonstrate the > problem: > > Create a new project with one form. Set Form1's height to 3600 > > Add a command button with a height of 495 and set it's top to 2640 > > In Form1's resize event add the following line of code: > > Command1.Top = Me.Height - 960 > > Now run it. If your screen font size (set in the Windows Display > Properties > > dialog) is set to "Normal" then as you resize the form the command button > > remains right on bottom of your form. But if you set the screen font size > > to "Large Fonts" or "Extra Large Fonts" then the button's bottom sinks > > slightly off the form. > > So my question is, how can I make this sample above smart enough to > account > > for the system's display font size? My example above was put together > under > > Windows XP so if the behavior differs from my description let me know... > > Thanks! > > Dan
> > (take out "TheTrash" to respond via email)
|
Sat, 11 Sep 2004 05:58:14 GMT |
|
 |
Mike William #4 / 7
|
 How do you determine the screen font size?
That's what I like! A nice little code example is worth it's weight in gold. You can check the Windows font size setting very easily by looking at the TwipsPerPixel property of the Screen. The TwipsPerPixel value is directly related to the Windows font size. In fact, it is inversely proportional to it. For the standard "Small Fonts" setting there are 15 Twips per pixel, and for the standard Large fonts setting there are 12 Twips per pixel. Since the display always has "square" pixels then the TwipsPerPixelX and the TwipsPerPixelY values are always the same. With printers, however, they can be different (although they are the same on most modern printers). Other font setting (of which there can be many) will return other values. A Twip, by the way, is 1/1440 of an inch (or one twentieth of a Point). These "inches" are, of course, "logical" inches (since Windows has no way of knowing the physical size of your monitor). A Windows "logical" inch on the printer, however, is the same as a "real" inch (because Windows *does* know the size of an A4 piece of paper, and so does your printer! Anyway, I digress (but then I've had a drink or two!). Dim n as Single n = Screen.TwipsPerPixelX However, you do not need to know the Windows font size (or the TwipsPerPixel value) in order to overcome your specific problem. All you need to do is to position your controls relative to the top left corner of the "client area" of your Form (rather than the top left corner of the Form itself). The "client area" excludes the borders and the Title Bar. It is the "usable" area of your Form. Actually, the Height (or Width) of your Form is *always* returned in Twips, whereas the Height (or Width) of the "client area" (the ScaleHeight or the ScaleWidth) is returned in whatever units you have set for the Form's ScaleMode property. In this little example, it is best, therefore, to leave the Form's ScaleMode set at its default value of Twips: Private Sub Form_Resize() Command1.Top = Me.ScaleHeight - Command1.Height End Sub If you are using a ScaleMode of Twips then the above code will keep the Command Button "glued" to the bottom of the Form, irrespective of the Windows font size setting. Mike
Quote: > I've been through the MSDN as well as Microsoft's knowledge base and not > found this yet. I need a way of determining what the user has sent the > Windows display font size to (from the Display Properties dialog, > Appearance tab, Font size - normal, large, extra large). The reason is that > it makes a difference in my form's height property depending on the size of > the font in the caption. This affects how I am moving around controls on > the form when the user resizes it (move button to coordinate x based on > form.height). ' > In case I'm not being clear, here is an example to demonstrate the problem: > Create a new project with one form. Set Form1's height to 3600 > Add a command button with a height of 495 and set it's top to 2640 > In Form1's resize event add the following line of code: > Command1.Top = Me.Height - 960 > Now run it. If your screen font size (set in the Windows Display Properties > dialog) is set to "Normal" then as you resize the form the command button > remains right on bottom of your form. But if you set the screen font size > to "Large Fonts" or "Extra Large Fonts" then the button's bottom sinks > slightly off the form. > So my question is, how can I make this sample above smart enough to account > for the system's display font size? My example above was put together under > Windows XP so if the behavior differs from my description let me know... > Thanks! > Dan
> (take out "TheTrash" to respond via email)
|
Sat, 11 Sep 2004 06:10:23 GMT |
|
 |
Dan #5 / 7
|
 How do you determine the screen font size?
Thanks Mike! That works perfectly. "ScaleHeight"... one of those properties I've seen in the intellisense list hundreds of times and never bothered to learn about! Imagine my chagrin... Thanks so much for your help! Dan -- http://www.Auction-Sentry.com
Quote: > That's what I like! A nice little code example is worth it's weight in gold. > You can check the Windows font size setting very easily by looking at the > TwipsPerPixel property of the Screen. The TwipsPerPixel value is directly > related to the Windows font size. In fact, it is inversely proportional to > it. For the standard "Small Fonts" setting there are 15 Twips per pixel, and > for the standard Large fonts setting there are 12 Twips per pixel. Since the > display always has "square" pixels then the TwipsPerPixelX and the > TwipsPerPixelY values are always the same. With printers, however, they can > be different (although they are the same on most modern printers). Other > font setting (of which there can be many) will return other values. A Twip, > by the way, is 1/1440 of an inch (or one twentieth of a Point). These > "inches" are, of course, "logical" inches (since Windows has no way of > knowing the physical size of your monitor). A Windows "logical" inch on the > printer, however, is the same as a "real" inch (because Windows *does* know > the size of an A4 piece of paper, and so does your printer! Anyway, I > digress (but then I've had a drink or two!). > Dim n as Single > n = Screen.TwipsPerPixelX > However, you do not need to know the Windows font size (or the TwipsPerPixel > value) in order to overcome your specific problem. All you need to do is to > position your controls relative to the top left corner of the "client area" > of your Form (rather than the top left corner of the Form itself). The > "client area" excludes the borders and the Title Bar. It is the "usable" > area of your Form. Actually, the Height (or Width) of your Form is *always* > returned in Twips, whereas the Height (or Width) of the "client area" (the > ScaleHeight or the ScaleWidth) is returned in whatever units you have set > for the Form's ScaleMode property. In this little example, it is best, > therefore, to leave the Form's ScaleMode set at its default value of Twips: > Private Sub Form_Resize() > Command1.Top = Me.ScaleHeight - Command1.Height > End Sub > If you are using a ScaleMode of Twips then the above code will keep the > Command Button "glued" to the bottom of the Form, irrespective of the > Windows font size setting. > Mike
> > I've been through the MSDN as well as Microsoft's knowledge base and not > > found this yet. I need a way of determining what the user has sent the > > Windows display font size to (from the Display Properties dialog, > > Appearance tab, Font size - normal, large, extra large). The reason is > that > > it makes a difference in my form's height property depending on the size > of > > the font in the caption. This affects how I am moving around controls on > > the form when the user resizes it (move button to coordinate x based on > > form.height). ' > > In case I'm not being clear, here is an example to demonstrate the > problem: > > Create a new project with one form. Set Form1's height to 3600 > > Add a command button with a height of 495 and set it's top to 2640 > > In Form1's resize event add the following line of code: > > Command1.Top = Me.Height - 960 > > Now run it. If your screen font size (set in the Windows Display > Properties > > dialog) is set to "Normal" then as you resize the form the command button > > remains right on bottom of your form. But if you set the screen font size > > to "Large Fonts" or "Extra Large Fonts" then the button's bottom sinks > > slightly off the form. > > So my question is, how can I make this sample above smart enough to > account > > for the system's display font size? My example above was put together > under > > Windows XP so if the behavior differs from my description let me know... > > Thanks! > > Dan
> > (take out "TheTrash" to respond via email)
|
Sat, 11 Sep 2004 06:23:41 GMT |
|
 |
Randy Birc #6 / 7
|
 How do you determine the screen font size?
OK .. two things. First, large fonts is represented by 120, not 72 as I previously mentioned. And there is also a KB article on this which basically says that any returned value may or may not reflect the true settings .... INFO: Large Fonts Versus Small Fonts Use in Windows Q177795 ---------------------------------------------------------------------------- ---- The information in this article applies to: Microsoft Win32 Software Development Kit (SDK) ---------------------------------------------------------------------------- ---- SUMMARY If your application has User Interface designs based on screen coordinates, you might frequently find that switching to large or small font drivers causes the design to look bad. If you try to remedy the problem by customizing the design to the system font size in use, you fail because the system does not know, and cannot report to an application, what font size the user has selected when configuring the video driver. MORE INFORMATION Video drivers for the Windows operating systems have historically offered the capability to operate in large fonts or small fonts. These "modes" differ in that the fonts used in the system and in applications appear larger on the display. Video drivers accomplish this by reporting different values for the LOGPIXELSY and LOGPIXELSX flags of the GetDeviceCaps() function. They also install a new set of system raster fonts that directly support the new display units. The operating system is not aware of this difference and is not specifically aware of whether the user has selected large fonts or small fonts. Thus, it cannot report which mode the system is currently in. Traditionally, video drivers report a value of 96 pixels per inch for small fonts LOGPIXELSX and LOGPIXELSY values and 120 pixels per inch for large fonts LOGPIXELSX and LOGPIXELSY values. However, this is not reliable because there is no standard dictating these values. Furthermore, Windows 95 allows the user to customize these return values to any arbitrary value. Other methods, such as the name of the video driver, have historically been used to infer large fonts versus small fonts use as well, but none of these methods are reliable. NOTE: The numbers and strings that appear in the Display Settings dialog box of the operating system are either managed by the display driver or merely data stored in the system registry. The presence of this data does not imply that the operating system can report it in a meaningful fashion. Applications should not attempt to determine the system font size since there is no reliable way to obtain the information. Typically, developers request this information because they have used screen coordinates to design the look of their application to a specific video display setting. The solution is to avoid using a device dependent means of specifying the application's user interface layout. Instead, you should use Dialog Base units as described by the Knowledge Base articles listed in the REFERENCES section of this article. These methods are portable from instance to instance of the operating system irrespective of large fonts, small fonts, or screen size. For more information on the best methods for dynamically creating dialog boxes and positioning controls please see the Knowledge Base articles listed in the REFERENCES section of this article. REFERENCES For additional information, please see the following articles in the Microsoft Knowledge Base: Last Reviewed: July 9, 2000 ? 2001 Microsoft Corporation. All rights reserved. Terms of Use. ---------------------------------------------------------------------------- ---- Send feedback to MSDN.Look here for MSDN Online resources. -- Randy Birch MVP Visual Basic http://www.mvps.org/vbnet/ Please respond only to the newsgroups so all can benefit. *** If you call the Sleep API in Bill's latest, will it have .NET dreams? ***
Quote: > Randy, > Doesn't work on XP (I don't know about other platforms). In the function > logPixels always = 96 regardless of what the display font is set to... > Dan > -- > http://www.Auction-Sentry.com
> > http://www.mvps.org/vbnet/code/screen/screenfont.htm > > Basically, if logPixels = 96, the user has small fonts. If = 72, the user > > has large fonts. If <> those values, the user has a custom setting as > > reflected in the logPix variable. > > -- > > Randy Birch > > MVP Visual Basic > > http://www.mvps.org/vbnet/ > > Please respond only to the newsgroups so all can benefit. > > *** If you call the Sleep API in Bill's latest, will it have .NET dreams? > > ***
> > > I've been through the MSDN as well as Microsoft's knowledge base and not > > > found this yet. I need a way of determining what the user has sent the > > > Windows display font size to (from the Display Properties dialog, > > > Appearance tab, Font size - normal, large, extra large). The reason is > > that > > > it makes a difference in my form's height property depending on the size > > of > > > the font in the caption. This affects how I am moving around controls > on > > > the form when the user resizes it (move button to coordinate x based on > > > form.height). ' > > > In case I'm not being clear, here is an example to demonstrate the > > problem: > > > Create a new project with one form. Set Form1's height to 3600 > > > Add a command button with a height of 495 and set it's top to 2640 > > > In Form1's resize event add the following line of code: > > > Command1.Top = Me.Height - 960 > > > Now run it. If your screen font size (set in the Windows Display > > Properties > > > dialog) is set to "Normal" then as you resize the form the command > button > > > remains right on bottom of your form. But if you set the screen font > size > > > to "Large Fonts" or "Extra Large Fonts" then the button's bottom sinks > > > slightly off the form. > > > So my question is, how can I make this sample above smart enough to > > account > > > for the system's display font size? My example above was put together > > under > > > Windows XP so if the behavior differs from my description let me know... > > > Thanks! > > > Dan
> > > (take out "TheTrash" to respond via email)
|
Sat, 11 Sep 2004 06:30:47 GMT |
|
 |
Mike William #7 / 7
|
 How do you determine the screen font size?
Quote: > Thanks Mike! That works perfectly. "ScaleHeight"... one of those > properties I've seen in the intellisense list hundreds of times and never > bothered to learn about! Imagine my chagrin...
Chagrin! I hope you're not swearing at me :-) Mike
|
Sat, 11 Sep 2004 06:50:57 GMT |
|
|
|