By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,890 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,890 IT Pros & Developers. It's quick & easy.

Thru code Determine if PC has Large/Small Fonts set

P: n/a
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";

Dec 19 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hello Joe,

Check the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\0001\Software\Fonts\LogPixels
value
Jtrying to write some code to determine if user has large/small fonts
Jset on
JPC
Jthought this would work but it didn't
JAny 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
Dec 19 '06 #2

P: n/a
"Joe" <hc******@yahoo.comwrote:
>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.

--
Lucian
Dec 19 '06 #3

P: n/a
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

"Michael Nemtsev" <ne*****@msn.comwrote in message
news:17***************************@msnews.microsof t.com...
Hello Joe,

Check the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware
Profiles\0001\Software\Fonts\LogPixels value
Jtrying to write some code to determine if user has large/small fonts
Jset on
JPC
Jthought this would work but it didn't
JAny 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


Dec 19 '06 #4

P: n/a
Hello Joe,

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

JHi
J>
JI think I am losing my mind :-)
J>
JI checked where you suggested and also some others
JThey are all set to 96 even though thru Properties->Apperance I have
Jlarge
Jfonts selected??????
JHKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
JHKLM\SYSTEM\CurrentControlSet\Hardware
JProfiles\Current\Software\Fonts\LogPixels
JHKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels
J>
J"Michael Nemtsev" <ne*****@msn.comwrote in message
Jnews:17***************************@msnews.microso ft.com...
J>
>Hello Joe,

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

Jtrying to write some code to determine if user has large/small
fonts
Jset on
JPC
Jthought this would work but it didn't
JAny 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
Dec 19 '06 #5

P: n/a
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
"Lucian Wischik" <lu***@wischik.comwrote in message
news:7c********************************@4ax.com...
"Joe" <hc******@yahoo.comwrote:
>>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.

--
Lucian

Dec 19 '06 #6

P: n/a
Joe
I tried it on 2 machines and even rebooted and it didn't change
I am running XP sp2

Weird :-)

"Michael Nemtsev" <ne*****@msn.comwrote in message
news:17***************************@msnews.microsof t.com...
Hello Joe,

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

JHi
JJI think I am losing my mind :-)
JJI checked where you suggested and also some others
JThey are all set to 96 even though thru Properties->Apperance I have
Jlarge
Jfonts selected??????
JHKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
JHKLM\SYSTEM\CurrentControlSet\Hardware
JProfiles\Current\Software\Fonts\LogPixels
JHKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels
JJ"Michael Nemtsev" <ne*****@msn.comwrote in message
Jnews:17***************************@msnews.microso ft.com...
J>
>>Hello Joe,

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

Jtrying to write some code to determine if user has large/small
fonts
Jset on
JPC
Jthought this would work but it didn't
JAny 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


Dec 19 '06 #7

P: n/a
"Joe" <hc******@yahoo.comwrote:
>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.

--
Lucian
Dec 19 '06 #8

P: n/a
"Lucian Wischik" <lu***@wischik.comwrote in message
news:7c********************************@4ax.com...
(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
Dec 20 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.