Re: Textbox/label sizing

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Jack Jackson" <jjackson@xxxxxxxxxxxxxxxx> wrote in message
news:9v8un3d19tv8f383cggtith4fhl7ponc15@xxxxxxxxxx
On Fri, 4 Jan 2008 23:11:52 -0500, "Michael Asherman" <mda@xxxxxxxxxx>
wrote:

"Jack Jackson" <jjackson@xxxxxxxxxxxxxxxx> wrote in message
news:nfttn3lhe140rk2ehhb524i1vbjuqaeb7g@xxxxxxxxxx
On Sat, 05 Jan 2008 00:08:17 GMT, Peter Huish <huish@xxxxxxxxxxxxxx>
wrote:


I have a form that I want to use in a number of places to allow the
entry of a variable length set of text. The form receives as parameters
the caption for a label and also an input mask for the textbox.

I resize the label, the textbox and the form and reposition controls to
make the form suit the variable length of the entry field. The length
of the data entered can vary from 4 characters to 30 characters.

Currently I am using an algorithm to size the label width and text field
that was worked out by guesswork and I was hoping that there may be a
more sensible way to caclulate the size.

What I want to know is the size of the label caption. Currently I
calculate the size of the caption as being Len(caption text) * 6. Is
there a more accurate method that I could use as I am sure that screen
resolutions and the like could cause this approach to fail.

Why don't you set the label AutoSize = .T.? The only thing you have
to watch out for is that in more recent versions (sometime after 3.0)
labels don't autosize when their Caption property is changed until the
first time the form is displayed, so if you need to set the caption in
Init() you have to wait until the first call to Activate before the
label's Width property is set properly.

Another choice is to set the ThisForm.Textxxx properties (FontName,
FontSize, FontBold, FontItalic, etc.) and call
Thisform.TextWidth(str).

There is also the TXTWIDTH() function, but it only returns the width
based on the average character size of the font, not the actual
characters.

I think you're wrong about that, Jack. The TXTWIDTH() function returns
the
actual text width, but in units of average character size. Using
FONTMETRIC(6) you can turn this into an exact width in pixels.

I've never used it, but on rereading the Help for it I think you are
right. In any event it won't be as accurate as Form.TextWidth() since
it returns a multiple of the average character size, but it is easier
to use than Form.TextWidth() since you don't have to set the various
form font properties.

Jack - take a look at VFP Help: the TXTWIDTH() function accepts optional
arguments for font characteristics, making it more flexible and no less
precise that the Form.TextWidth method.

Mike


.



Relevant Pages

  • Re: Textbox/label sizing
    ... I resize the label, the textbox and the form and reposition controls to ... make the form suit the variable length of the entry field. ... of the data entered can vary from 4 characters to 30 characters. ... What I want to know is the size of the label caption. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Textbox/label sizing
    ... I resize the label, the textbox and the form and reposition controls to ... make the form suit the variable length of the entry field. ... What I want to know is the size of the label caption. ... but in units of average character size. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Textbox/label sizing
    ... I resize the label, the textbox and the form and reposition controls to ... make the form suit the variable length of the entry field. ... of the data entered can vary from 4 characters to 30 characters. ... What I want to know is the size of the label caption. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Textbox/label sizing
    ... I resize the label, the textbox and the form and reposition controls to ... of the data entered can vary from 4 characters to 30 characters. ... What I want to know is the size of the label caption. ... There is also the TXTWIDTH() function, but it only returns the width ...
    (microsoft.public.fox.programmer.exchange)
  • Textbox/label sizing
    ... I resize the label, the textbox and the form and reposition controls to ... make the form suit the variable length of the entry field. ... of the data entered can vary from 4 characters to 30 characters. ... What I want to know is the size of the label caption. ...
    (microsoft.public.fox.programmer.exchange)