Page 1 of 1

How to make size of text not affected by Display Setting

Posted: Tue Aug 20, 2013 3:39 pm
by sjuwing
I am using DrawText() to handle text on UI. When people change the Display from 100% to 150% on Control Panel, the size of the text changes, and the alignment won't look right.
I am new to PB, so is there a way to fix the size, or an alternative to DrawText()?

Re: How to make size of text not affected by Display Setting

Posted: Tue Aug 20, 2013 4:49 pm
by Little John

Re: How to make size of text not affected by Display Setting

Posted: Tue Aug 20, 2013 4:56 pm
by TI-994A
sjuwing wrote:change the Display from 100% to 150% on Control Panel, the size of the text changes, and the alignment won't look right...
Hello sjuwing. For custom drawn forms, DrawText() is the way to go, although the environment variables have to be taken into consideration. Checking the display resolution before drawing the UI would solve such issues. Please take a look at this example which I posted about a month ago, and perhaps you'd get some idea. The routine determines the suitable font size before using it:

http://www.purebasic.fr/english/viewtop ... nt#p418173

Hope it helps. :)

Re: How to make size of text not affected by Display Setting

Posted: Tue Aug 20, 2013 9:27 pm
by sjuwing
Thank you both. It's helpful.
TI-994A's solution is more specific to my question. However, it ran into infinite loop sometimes. The revised version works for me.
I also tried another way. Since my app only targets to Windows (XP or above), so it looks works for me.

Code: Select all

Procedure ConvertFontSize(iRawSize.l)
  iDpi.l = GetDeviceCaps_(GetDC_(0), #LOGPIXELSX)
  iFontHeight.l = Int(iRawSize / 72 * iDpi)
  iNowSize.l = Int(iFontHeight / iDpi * 72)
  ProcedureReturn iNowSize
EndProcedure