[Prev][Next][Index][Thread]

Re: <text-field>, size, GDI context...



How and when do I call this? What context is required for text-size to
function correctly? I tried just calling this from a button on the form,
where the text field in question is fully instantiated and displayed,
and it just returns: #f, #f, #f, #f, #f.

Chris Double wrote:
> 
> Scott Ribe <sribe@miqs.com> writes:
> 
> > I'd like to set a <text-field> width in terms of a particular string,
> > not pixels. To do this I have to have a valid GDI context handle, and
> > the font of the text field, then make the call to get the string width,
> > and set the width of the text field accordingly.
> 
> The method 'text-size' may be useful. Maybe something like:
> 
> define method calculate-string-width( s, gadget )
>   let _port = gadget.port;
>   let style = get-default-text-style(_port, gadget);
>   let largest-x =
>     with-sheet-medium( medium = gadget )
>       text-size(medium, "Hello World", text-style: style);
>     end;
> end method;
> 
> This will return the width of the string given the text style for the
> gadget (assuming the gadget is a <text-field> for example). text-size
> also returns other data that may be of interest (height, etc).
> 
> Chris.



Follow-Ups: References: