How to make size of text not affected by Display Setting

Just starting out? Need help? Post your questions and find answers here.
sjuwing
User
User
Posts: 11
Joined: Thu Aug 08, 2013 9:16 pm

How to make size of text not affected by Display Setting

Post 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()?
User avatar
TI-994A
Addict
Addict
Posts: 2791
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

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

Post 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. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
sjuwing
User
User
Posts: 11
Joined: Thu Aug 08, 2013 9:16 pm

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

Post 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
Post Reply