realbasic-nug
[Top] [All Lists]

Re: TextHeight in EditField

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: TextHeight in EditField
From: Charles Yeomans <charles at declareSub dot com>
Date: Sun, 30 Apr 2006 09:40:07 -0400
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <DFFFED35-C21B-4028-AF53-3162B4785C5F at u dot washington dot edu>

On Apr 30, 2006, at 1:21 AM, David Linker wrote:

I think there must be an elegant way of doing this, but it escapes me.

I want to dynamically resize an editfield based on the text placed in it. Currently I use the textsize + 4 as an estimate of the height, and find the last line of the text and multiply.

I think that using TextHeight would be more accurate, but it appears only to be a property of a Graphics object, and I can't find a way of recovering the graphics object either of the editfield or it's enclosing window.

I would like this to be flexible, and cross-platform, if it is not horrendously difficult.


Here is a function that returns the text height.

Function TextHeight(fontName as String, fontSize as Integer) as Integer
  dim p as new Picture(1, 1, 32)
  If p.Graphics is nil then //file a bug report
    Return 0
  End if
  p.Graphics.TextFont = fontName
  p.Graphics.TextSize = fontSize
  Return p.Graphics.TextHeight
End Function

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>