Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Font Size --> Pixels?

528 views
Skip to first unread message

Jacob Thurman

unread,
May 30, 2003, 2:48:27 AM5/30/03
to
Canvas.TextWidth and Canvas.TextHeight are what you want.
--
Jacob Thurman
Creator of Castalia - The ultimate Delphi Productivity Suite.
http://www.delphi-expert.com/products/castalia
Super-Smart Syntax Highlighting
Fast, powerful code templates
Code Navigation Facilities you've only dreamed of
On-the fly syntax checking

"Bob" <borla...@pless.net> wrote in message
news:3ed6...@newsgroups.borland.com...
> How do I get the pixel height/width from a font size? As I change the font
> size of a control I also want to increase the size of the control
> proportionally?
>
> Thanks, -Bob
> Delphi 6
>
>


Bob

unread,
May 30, 2003, 2:33:28 AM5/30/03
to

Bob

unread,
May 30, 2003, 3:17:41 AM5/30/03
to
Only problem is the control may be empty. For example, if I have a TEdit
object 15x50, font changed from 8 to 12 point, how do I grow the control to
accomadate the same amount of text it would have held at 8p now at 12p?
Also, not sure how to access the control's canvas property and TextWidth
method.

Peter Below (TeamB)

unread,
May 30, 2003, 7:14:55 AM5/30/03
to
In article <3ed70595$1...@newsgroups.borland.com>, Bob wrote:
> Only problem is the control may be empty. For example, if I have a TEdit
> object 15x50, font changed from 8 to 12 point, how do I grow the control to
> accomadate the same amount of text it would have held at 8p now at 12p?
> Also, not sure how to access the control's canvas property and TextWidth
> method.

You don't need the controls canvas, you can use the forms canvas:

// in a method of the form
canvas.font := edit1.font;
h:= canvas.textHeight('Äy');
// h has the height of a string in the edits font.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Kurt Barthelmess (TeamB)

unread,
May 30, 2003, 7:02:26 AM5/30/03
to
"Bob" <borla...@pless.net> wrote:

>Only problem is the control may be empty.

You can still ask for the TextWidth and TextHeight - pass your own
text.

>For example, if I have a TEdit
>object 15x50, font changed from 8 to 12 point, how do I grow the control to
>accomadate the same amount of text it would have held at 8p now at 12p?

Set the Size property of the font to the point size and that should
change the Height property to pixels. But the sign will be inverted.
You'll need to add some padding for the border depending on
BorderWidth, BorderStyle, Ctl3D, etc.

>Also, not sure how to access the control's canvas property and TextWidth
>method.

Not all controls have a Canvas property. But you can use any control
(that does) with the same font.

Good luck.

Kurt

Geoff

unread,
May 31, 2003, 1:57:29 AM5/31/03
to Bob
Hey hang on....
I know that there are some odd fonts that don't change strictly correctly,
but if you know the font size before and after you know the ratio to increase
the size of the control.

Going from 8pnt to 12pnt has increased the size of the text by 50% (1.5 times)
so you should be able to increase the control size by 50%.

1 pnt = 1/72 inch. 8 pnt = 1/9th inch 12pnt = 1/6th inch and so on.

Note of course that if you leave AutoSize on for labels they will automatically
increase in size, both vertical and horizontal. Edit boxes will increase in
height only. So if you want to change them programmatically then you will need
to switch this feature off.

Geoff

0 new messages