Board index » delphi » String width function?

String width function?

Hi, all!

As I remember I saw a function in Delphi-3
that returns me a width of my string in pixels
for the assigned font and it's attributes.
Now I need this but can't find.
What is that function?

So, what I want to do is something like this:

    MyButton.Width := what_function (' Button caption ', 'Arial 10, bold');

Oleg
o...@ca-ib.com

 

Re:String width function?


Quote
Oleg Roshchin wrote:

> Hi, all!

> As I remember I saw a function in Delphi-3
> that returns me a width of my string in pixels
> for the assigned font and it's attributes.
> Now I need this but can't find.
> What is that function?

> So, what I want to do is something like this:

>     MyButton.Width := what_function (' Button caption ', 'Arial 10, bold');

> Oleg
> o...@ca-ib.com

A canvas has a method TextWidth. Is this what you mean?

  tw:=Canvas.TextWidth('Some text');

It returns the width of the text (in the current font of the canvas) in
pixels. There's also TextHeight().

Sasan.

Re:String width function?


See TCanvas.TextExtent

Re:String width function?


Yes you need the Canvas.TextWidth(String1) method.
A TButton does not have a public Canvas but you can use the Canvas of the
form instead if the font of the button is the same as the fornt of the form:
  Form1.Canvas.TextWidth(Button1.Caption)

Goodluck
Robert
the Netherlands

Oleg Roshchin heeft geschreven in bericht <79u0tm$cg...@news.netway.at>...

Quote
>Hi, all!

>As I remember I saw a function in Delphi-3
>that returns me a width of my string in pixels
>for the assigned font and it's attributes.
>Now I need this but can't find.
>What is that function?

>So, what I want to do is something like this:

>    MyButton.Width := what_function (' Button caption ', 'Arial 10, bold');

>Oleg
>o...@ca-ib.com

Other Threads