Qbasicnews.com
Center Text - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Center Text (/thread-9297.html)



Center Text - Champions_2002 - 05-18-2006

Can anybody tell me how to center text please


Center Text - phycowelder - 05-18-2006

Take how many pixels your screen is wide
divide by 2 for center
then divide by 8 for CHAR spaces to center
then take yout string and divide by 2
minus that from your screen center!
then plug you final number in to LOCATE X,Y

eg
TEXT$="HELLO WORLD!" <----- string length is 12
screen length=640

640/2=320
320/8=40 <--- screen center for TEXT
12/2=6 <------ Text center
40-6=34 <--- text start for centered text!

LOCATE 34,1TongueRINT TEXT$ <------ it is now centered!


if you want just a comanded you would either have to write one
or look for a library.


Center Text - Torahteen - 05-18-2006

So using his example, you can make a simple SUB to print centered text on the screen:

Code:
DECLARE SUB printc(text AS STRING, y AS INTEGER)
DIM l AS INTEGER
DIM c AS INTEGER

l = LEN(text)     'Get's length of our string
c = l/2

LOCATE y, 40-c
PRINT text
END SUB

*Note: This has not been tested, there may be errors.


Center Text - TheAdventMaster - 05-18-2006

You could also look up and use drawstring from the wiki Big Grin


Center Text - Zack - 05-19-2006

Anyone have an app to load standard Windows fonts into an image buffer for DRAW STRING use?


Center Text - TheAdventMaster - 05-19-2006

Quote:Anyone have an app to load standard Windows fonts into an image buffer for DRAW STRING use?
This thread might interest you:

http://www.freebasic.net/forum/viewtopic.php?t=1713