Page 1 of 1

Truncate the Level of the button To next line

Posted: Thu Apr 09, 2015 8:11 am
by pkmittal
Hi, If the level of the button is long and I want to truncate it to next line (by increasing the height of the width) then how can we do this in live code?

Re: Truncate the Level of the button To next line

Posted: Thu Apr 09, 2015 11:44 am
by Klaus
Hi pkmittal,

I think you mean the LABEL of a button? 8)

You can do this:
1. With the messagebox (or any other script
set the label of btn 1 to ("This is line 1" & CR & "This is line 2 of the label")

2. In the inspector for the button enter BACKSLASH-N \n to add a new line:
This is line 1\nThis is line 2 of the label

Hope I understood you correctly.


Best

Klaus

Re: Truncate the Level of the button To next line

Posted: Thu Apr 09, 2015 3:17 pm
by pkmittal
Thanks. But I want to do it automatically if the label of the button does not fit in the width of the button then it should show the remaining next in new line..

So depending on width of the button, It should show the truncate the label from one line to another line..

Re: Truncate the Level of the button To next line

Posted: Thu Apr 09, 2015 3:19 pm
by Klaus
Ah, get it now! :D
Sorry, no idea how to do that..

Re: Truncate the Level of the button To next line

Posted: Thu Apr 09, 2015 7:52 pm
by jacque
Try this:

Code: Select all

on setLabel pLbl
  set the label of btn 1 to pLbl
  if the formattedwidth of btn 1 > the width of btn 1 then
    put the number of words in pLbl div 2 into tMiddle
    put word 1 to tMiddle of pLbl & cr & word (tMiddle + 1) to -1 of pLbl into pLbl
  end if
  set the label of btn 1 to pLbl
end setLabel

Re: Truncate the Level of the button To next line

Posted: Thu Apr 09, 2015 8:14 pm
by dunbarx
Hi.

Jacque's trick should work. But what if the label requires three or more lines? It may never, but I bet you would get a kick out of writing a general solution, based on her methods.

Craig Newman

Re: Truncate the Level of the button To next line

Posted: Mon Apr 13, 2015 1:09 pm
by pkmittal
Thanks a lot for your help