Getting the 'FormattedWidth' of a Tab Button
Mac OS 9 Mac OS X Windows Linux

> I'm just trying to find out how wide I have to make the button in order
> to see all the tabs. Unlike other button styles, a tabbed button shows
> all lines of its contents, but the formattedWidth property only returns
> the width of one line of the contents. I'd like to get the width of
> all the contents as they're displayed horizontally.
>
> Thanks for your concern. Let me know if you've got any ideas.

Here you go... try this:
on mouseUp
  put tabFormattedWidth(long id of btn 1) into tWidth
  set the width of btn 1 to tWidth
end mouseUp

function tabFormattedWidth pBtnDesc
  put the text of pBtnDesc into tTabs
  lock screen
  put 0 into tWidth
  put the number of lines of tTabs into tNum
  put the label of pBtnDesc into tOrigLabel
  repeat with x = 1 to tNum
    set the label of pBtnDesc to (line x of tTabs)
    put the formattedWidth of pBtnDesc into tFW
    add tFW to tWidth
  end repeat
  put tWidth + (18* tNum) into tWidth
  set the label of pBtnDesc to tOrigLabel
  unlock screen
  return tWidth
end tabFormattedWidth
Posted 2/8/2006 by Ken Ray to the MetaCard List