Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to get size of text (Read 3113 times)
MalcolmW
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Nov 22nd, 2006
How to get size of text
Nov 22nd, 2006 at 3:58pm
Print Post  
Hi All,

Simple question... How can I find out the length of a single line of text in a box?

I can see how to organise multiple lines to a given width but not how to find the width of one line.

Thanks in advance
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to get size of text
Reply #1 - Nov 22nd, 2006 at 5:37pm
Print Post  
Hi,

Do you mean that you need to set the box width so that all text fits on a single line?

Stoyan
  
Back to top
 
IP Logged
 
MalcolmW
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Nov 22nd, 2006
Re: How to get size of text
Reply #2 - Nov 23rd, 2006 at 6:58am
Print Post  
Hi Stoyan,

Yes the width of a box containing some text on one line.

I have a collection of boxes each containing text and an image. I need to find the width of the longest piece of text so that I can set all the boxes the same size then arrange them in the window.
I don't know what the text is until runtime so I can not preset the width correctly.

Rgds,  Malcolm
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to get size of text
Reply #3 - Nov 23rd, 2006 at 10:56am
Print Post  
Hi Malcolm,

There isn't any method provided by FlowChartX that will let you measure the text width. You might either use the Windows API to do that, or run FitToText in a loop as shown below.

Code
Select All
Private Sub Form_Load()
    Overview1.Document = fcx

    Set b = fcx.CreateBox(20, 20, 20, 20)
    b.Text = "Where it comes and where it goes"
    b.TextStyle = tsCenterML
    fitTextOnLine b
End Sub

Private Sub fitTextOnLine(ByVal b As box)
    b.SetSize 10000, 1
    b.FitSizeToText

    Dim singleLineHeight As Long
    singleLineHeight = b.bottom - b.Top

    Dim w As Long
    w = 30
    b.SetSize w, singleLineHeight
    b.FitSizeToText

    Do While b.bottom - b.Top > singleLineHeight
     b.SetSize w, singleLineHeight
     b.FitSizeToText
     w = w + 10
    Loop
End Sub
 



FitSizeToText behaves in different ways depending on the TextStyle. The method above will work with the ts*ML styles.

Stoyan
  
Back to top
 
IP Logged
 
MalcolmW
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Nov 22nd, 2006
Re: How to get size of text
Reply #4 - Dec 4th, 2006 at 6:51am
Print Post  
Thanks Stoyan,

Not ideal but gets the job done.

Rgds,

Malcolm
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint