Thru code Determine if PC has Large/Small Fonts set

J

Joe

Hi

trying to write some code to determine if user has large/small fonts set on
PC
thought this would work but it didn't

Any suggestions???
Thanks
Graphics g = Graphics.FromHwnd(this.Handle);

if(g.DpiX == 96)

sFonts = "System running Small/Normal Fonts";

else if (g.DpiX == 120)

sFonts = "System running Large Fonts";
 
M

Michael Nemtsev

Hello Joe,

Check the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\0001\Software\Fonts\LogPixels
value


J> trying to write some code to determine if user has large/small fonts
J> set on
J> PC
J> thought this would work but it didn't
J> Any suggestions???
J>
---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangel
 
L

Lucian Wischik

Joe said:
trying to write some code to determine if user has large/small fonts set on
PC. Thought this would work but it didn't

It does work more or less. e.g. The following code works perfectly:

Graphics g = Graphics.FromHwnd(this.Handle);
MessageBox.Show(g.DpiX.ToString());

Your code had two problems:

(1) Graphics.DpiX is a float. You can't really test whether a float is
== to another number, not in any language. That's because a float like
"120" will internally be stored as something like 119.9999999997. You
should only ever test whether a float is within a certain margin of
the other number. People usually call that margin "epsilon".

(2) Font size isn't restricted to 96 and 120. It's a continuum. On my
system, for example, font size is set to 144. (Hey, I'm getting old
and my eyesight's fading!)

Basically, if your program depends on knowing whether it's small or
large fonts, then it probably has bad design. You might try explaining
what you're trying to achieve by testing Dpi, and others might be able
to assist.
 
J

Joe

Hi

I think I am losing my mind :)

I checked where you suggested and also some others
They are all set to 96 even though thru Properties->Apperance I have large
fonts selected??????


HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
HKLM\SYSTEM\CurrentControlSet\Hardware
Profiles\Current\Software\Fonts\LogPixels
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels
 
M

Michael Nemtsev

Hello Joe,

Have u pressed the Refresh in regedit after u applied new DPI?
In my environment I got new value

J> Hi
J>
J> I think I am losing my mind :)
J>
J> I checked where you suggested and also some others
J> They are all set to 96 even though thru Properties->Apperance I have
J> large
J> fonts selected??????
J> HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
J> HKLM\SYSTEM\CurrentControlSet\Hardware
J> Profiles\Current\Software\Fonts\LogPixels
J> HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels
J>
J> J>
Hello Joe,

Check the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware
Profiles\0001\Software\Fonts\LogPixels value

J> trying to write some code to determine if user has large/small
fonts
J> set on
J> PC
J> thought this would work but it didn't
J> Any suggestions???
J> ---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelangelo
---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangel
 
J

Joe

Hi

Thanks for the info.

I was basically only do this to help with debugging some UI issues in
development.
If a user is having a UI problem I just wanted this info to eliminate it
from consideration.

The interesting issue is that - I run the code on 2 machine 1 with Large
Fonts and another with small Fonts
The code I wrote and also looking at the registry are all set to 96 ???? I
am confused

I set fonts thru Properties->Appearance

Thanks
 
J

Joe

I tried it on 2 machines and even rebooted and it didn't change
I am running XP sp2

Weird :)

Michael Nemtsev said:
Hello Joe,

Have u pressed the Refresh in regedit after u applied new DPI?
In my environment I got new value

J> Hi
J> J> I think I am losing my mind :)
J> J> I checked where you suggested and also some others
J> They are all set to 96 even though thru Properties->Apperance I have
J> large
J> fonts selected??????
J> HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
J> HKLM\SYSTEM\CurrentControlSet\Hardware
J> Profiles\Current\Software\Fonts\LogPixels
J> HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels
J> J>
Hello Joe,

Check the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware
Profiles\0001\Software\Fonts\LogPixels value

J> trying to write some code to determine if user has large/small
fonts
J> set on
J> PC
J> thought this would work but it didn't
J> Any suggestions???
J> ---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelangelo
---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
L

Lucian Wischik

Joe said:
I set fonts thru Properties->Appearance

Ah. Properties>Appearance doesn't change the DPI. It only picks a
larger font size for certain UI elements. So these UI elements will be
larger while everything else remains the same.

Settings>Advanced>DPISetting will chang the DPI. It alters the scale
of EVERYTHING in the UI (fonts, scrollbars, buttons, ...). This DPI is
what's used by windows to scale dialogs.
 
P

Peter Duniho

Lucian Wischik said:
(1) Graphics.DpiX is a float. You can't really test whether a float is
== to another number, not in any language. That's because a float like
"120" will internally be stored as something like 119.9999999997.

That's not exactly true. For small enough integer values (where "small
enough" depends on the size of the mantissa), they can be represented
exactly as floating point, and are.

120 is stored internally as 120. If you know in advance that you are
dealing with floating point values that can be and are represented exactly,
you can do a direct comparison.

Another alternative to comparing within an epsilon value is to simply round
the float to the nearest integer. Of course, this only works when the
numbers you are comparing are supposed to be integers in the first place.
:)

Not that this has anything to do with this thread, but I just had to stick
my nose in. :)

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top