Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Center Text
#1
Can anybody tell me how to center text please
Reply
#2
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.
t is better to error on the side of caution
than the side of haste!!!
[Image: title3.jpg]
Reply
#3
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.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#4
You could also look up and use drawstring from the wiki Big Grin
Reply
#5
Anyone have an app to load standard Windows fonts into an image buffer for DRAW STRING use?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#6
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)