Centering Text

Discuss PocketC for Palm OS (including Desktop Edition)

Postby nomar on Tue May 08, 2001 4:12 pm

Does anyone know a way to center text in an area or find the pixel width of a string? I need to be able to center some text for a program I am creating, and if anyone knows how, that would be great.
Posts: 28
Joined: Thu Apr 19, 2001 11:20 pm

Postby retropolis on Tue May 08, 2001 9:38 pm

You can align text the following way...


where V describes the vertical alignment and H describes horizontal. Values for V can be (0) top (1) center (2) baseline. Values for H can be (0) left, (1) center or (2) right.

e.g. if you wanted to center "hello world" on the screen with it's baseline resting on pixel 80 you would do the following:

text(80,80,"hello world");

Use textwidth("hello world"); to return the width of the string "hello world" in pixels using the current font settings determined by textattr().

Hope this helps!

30 years behind the competition.
30 years behind the competition.
Posts: 18
Joined: Mon Mar 12, 2001 7:58 pm
Location: USA

Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 4 guests