validate Text width within a label whose font can change

  • Thread starter Thread starter Jason T
  • Start date Start date
J

Jason T

i have a label on a report who's caption reads "Total: "
(caption does not change).
the font size of the label can be dynamically changed by a
form where different criteria are selected to edit the
report before it is printed.
as font size increases the width of the label needs to
increase accordingly.

i considered using the windows api
function 'GetTextExtentPoint' along w/ the 'GetDC'
function. i think if i could pass the label through
the 'GetDC' function and then through
the 'GetTextExtentPoint' it would work, but i dont know
how do this. if it were a form i could use the 'GotFocus'
api function, but with it being a report i'm outta luck.

does anyone have information that can help me with the
route i'm taking, or have another way that you know will
work??? thank you! Jason
 
Try this:

You probably have a max and min font size. So step trough it, and record the
difference in width that the label needs to increase. Something like size 12
increase .1 inch, size 14 increase .2 inch, etc. You'll see most times the
rate is the same. All you have to do then is adjust the size of the label by
whatever rate is needed for the new font size (at the same time you are
changing the font size).

Or the easy way: I usually align to the right the labels on my forms and
reports, and make the size of the label extra big.
You never notice this because the extra spaces are on the left of the label,
so the distance between your label and the data doesn't change. In your
case, if the size increases, it doesn't matter because it will still fit.

Rodrigo.
 
See:
http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth
and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line
to simulate RTF style text.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Back
Top