Draw rectangle around text in text box

P

Peter Wetschnigg

Hello,

on a report's groupheader i have a textbox which i would like to be framed
by a rectangle depending on the width of the text it contains. I now use
the TextWidth function within the following code:

Private Sub Gruppenkopf0_Print(Cancel As Integer, PrintCount As Integer)
Breite = Me.TextWidth(Me.Text20)
Me.Line (Text20.Left, Text20.Top)-((Text20.Left + Breite), (Text20.Top
+ Text20.Height)), , B
End Sub

But the TextWidth function doesn't seem to calculate the width of the text
in the textbox properly, it is too small. If I multiply the result (Breite)
by 1.6 I get a good, but still not exact result in most cases. Am I missing
something?

Best regards,
P. W.
 
S

Stephen Lebans

In order to correctly call the Report object's TextWidth method you have to
set the Report object's font related properties to match those of the
TextBox control in question. In this case though, you do not need to call
the TextWidth method at all. Since you are invoking your code within the
Section's Print event you can simply use the TextBox control's dimensions.
For example:
Me.Line (Text20.Left, Text20.Top)-((Text20.Left + Text20.Width ),
(Text20.Top + Text20.Height)), , B

For working sample code that handles CanGrow situations across multiple
pages see:
http://www.lebans.com/PrintLines.htm
Scroll down to the older A97 version for a simpler solution.

--

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

Peter Wetschnigg

Stephen said:
In order to correctly call the Report object's TextWidth method you have to
set the Report object's font related properties to match those of the
TextBox control in question.

That hit the spot! Now the width is calculated correctly. Thanks a lot!
In this case though, you do not need to call
the TextWidth method at all. Since you are invoking your code within the
Section's Print event you can simply use the TextBox control's dimensions.
For example:
Me.Line (Text20.Left, Text20.Top)-((Text20.Left + Text20.Width ),
(Text20.Top + Text20.Height)), , B

If I do this, the framing rectangle widens to the far right of the report,
even if the text it contains is much shorter.
For working sample code that handles CanGrow situations across multiple
pages see:
http://www.lebans.com/PrintLines.htm
Scroll down to the older A97 version for a simpler solution.

Great site, I will check this out. There doesn't seem to be anything you
can't handle. :)

Regards,
P. W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top