Re: adjusting fonts to computer's dpi settings
- From: "Mike Williams" <mikea@xxxxxxxxxxxxxxxxx>
- Date: Tue, 5 Feb 2008 09:09:33 -0000
"Jack" <replyto@it> wrote in message news:u$%23mFG5ZIHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
After watching my app under 120 dpi I came to conclusion
that if I summarily change the font to MS Serif and decrease
font size to 6 it will correct all wrong places.
Is it possible to do something like this:
On Error Resume Next
Dim C as Control
For Each C In Controls
C. Font.Name = MS Serif ' etc, etc
Yes, it is possible to run through the Controls changing font sizes in that manner, but personally I would not advise doing so, at least until you have looked into this problem a little further. Everything in a VB .frm file and a VB .exe file records the size and position of the Form's client area and of all its contained controls using twips (regardless of any ScaleModes you might be using). Then at run time it converts those twip values into pixels using the twips per pixel setting of the machine on which the code is currently running (15 twips per pixel on a 96 dpi machine, 12 twips per pixel on a 120 dpi machine, etc, etc) and it sets both their size and position in accordance with the returned values. This means that the entire Form and all of its controls have a larger size (in terms of the pixels they occupy) on a 120 dpi (12 tpp) machine than they do on a 96 dpi (15 tpp) machine, but that everything (the Form and all its contained controls) all still fit together nicely. In effect it is as though you were looking at the original Form (on a 96 dpi machine) through a magnifying glass. VB still uses the same design time point sizes for the fonts on your various controls (points and twips have the same fixed relationship to each other on all machines) so the fonts magnify by the same amount (within certain well known font size limitations). That's because all applications that request a font from the system must use pixel values to express the desired font size, and so the pixel size of the fonts is magnified by the same amount as the magnification of the Form and its controls (got a bit tongue tied there, but I'm sure you know what I mean!). The end result is that the VB Form and all its contained controls and all the fonts displayed on those controls all still work together nicely and are all laid out and positioned in the same pattern (apart from a few little snags which can sometimes occur because of the way font sizes and character widths are all constrained to be whole pixel values, but it is easy to prevent those little snags becoming a problem) It is as though you are looking at the entire Form and everything on it through a magnifying glass (compared to how it was on the 96 dpi display)
All of this of course is fine for a Form that is smaller than the screen in both cases (96 dpi and 120 dpi machines), but not for a much larger Form or for a maximized Form, because in those cases VB will be unable to make the Form as large as it would like to (because it is limited to the size of the display) but it will still fully resize all of its contained controls, and so you end up in those cases with controls near the bottom and right edges of the Form disappearing from view entirely. The purpose of most resizing controls is to attend to these problems, but being "general purpose" there is no way that they can work correctly under all circumstances and so it is usually better to write your own code to attend to this stuff at run time, taking into account any peculiarities of your own application. You don't need to bother doing that of course if your Form is smaller than the display even on a 120 dpi machine.
Anyway, it would be interesting to see exactly what is happening on your own machine to make this stuff go wrong, so I look forward to seeing those scren shots we talked about.
By the way, regarding the exe file I asked you to create for the Form on your screen shots, would you place the following code in the Form:
Option Explicit
Private Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow _
Lib "user32" () As Long
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nindex As Long) As Long
Private Const LOGPIXELSX As Long = 88
Private Sub Form_Load()
Dim DC As Long
DC = GetDC(GetDesktopWindow)
AutoRedraw = True
Print "twip per pixel = " & Screen.TwipsPerPixelX
Print "dots per inch = " & ScaleX(1, vbInches, vbPixels)
Print "Log pixels X = " & GetDeviceCaps(DC, LOGPIXELSX)
End Sub
Mike
.
- References:
- adjusting fonts to computer's dpi settings
- From: Jack
- Re: adjusting fonts to computer's dpi settings
- From: Mike Williams
- Re: adjusting fonts to computer's dpi settings
- From: Jack
- adjusting fonts to computer's dpi settings
- Prev by Date: Re: OCX, Classes, DLL's - Which?
- Next by Date: Re: Newbie nervous about OCXes and reliability.
- Previous by thread: Re: adjusting fonts to computer's dpi settings
- Next by thread: copyin directory structure from one drive to another
- Index(es):
Relevant Pages
|