Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to verticle centre text in textbox on a label [report]

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi! I'm having a textbox on a report in which a number of lines may be printed [new line generated by chr(13)]. Font and fontsize is user selection. Now I'm looking for a way to vertical centre this text in the textbox. I do think that fontmetric should be able to decide height of a line. Count of the number of chr(13) decides number of lines. Height of textbox is to be retrieved by hacking the frx. Now the Q is how to get the algortm to retrieve the number of chr(13) which must be placed in front of the textstring to be printed.
Any suggestions?
TIA Bart
 
Hi Bart,

just in case you dont (want)use Reportbehavior90, you may also make use of function v1:

try in your command window:

myAvatar = "Jockey 2"
? myAvatar function "v1"

Groet,
Koen
 
Hi Koen,

That's an undocumented function?
I'm using VFP about 15 years now but never seen this feature before...

-Bart
 
Bart said:
That's an undocumented function?
I'm using VFP about 15 years now but never seen this feature before...

It's standard syntax for the ? command. The command takes a FUNCTION clause, which takes one or format codes. These are same codes used in the PICTURE clause and in TRANSFORM(). In this case, the code "v1" specifies a vertical field, one character wide.

So, no. It is not undocumented.

However, I don't think it will solve your problem, as you have already worked out how to break the lines in your textbox.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Jockey2, this is what Bart intends to solve:

Aligning text vertically:

Top:
1. row --- Text Line 1---
2. row --- Text Line 2---
3. row
4. row
5. row
6. row

Bottom:
1. row
2. row
3. row
4. row
5. row --- Text Line 1---
6. row --- Text Line 2---

These two are easy, as you can anchor a report textbox to top or bottom of the detail band

Vertically centered:
1. row
2. row
3. row --- Text Line 1---
4. row --- Text Line 2---
5. row
6. row

So this is not about rotating nor writing text vertically, but centering it certically.

The additional problem is, there are not always 6 rows, that depends on Label height and Fontsize.

Bart can set the report text control height by hacking into the FRX data itself, so the detail band and report control have the right height (and width of course, but that's secondary).
Knowing that height I'd say from all I have read and learned here, the line height compared to the detail band or report textbox height is Fontsize*1000/72 and so you can calculate how many lines fit in the label in total, you can also calculate how many lines the text to be printed will be, eg count how many CRs are in it, and then you can calculate how many CRs you need to prefix the text, so it's not printed at the top of the label, but vertically centered.

Bart, I hope you don't mind if I explained the problem again herewith. I think it's almost solved, you just have to experiment with this a bit and see if it really works out. A detail problem may be you have your text without CRs, still it's wrapped into some lines by the width of the label/report control. That's not so easy to solve, if the font is proportional and not monospaced.

Bye, Olaf.
 
Well, thanks for your explanation Mike.
In fact the ? command I never use it in an application. So that's why I thought about undocumented feature....
-Bart
 
Fontsize*1000/72 -> Fontsize*10000/72

The factor is 10000 in whatever unit name per inch for FRX objects in their VPOS, HPOS, Height and Width fields. And a font pt is 1/72, therefore the factor 10000/72.

So:
totallines = Reportcontrolrecord.Height*72/(Fontsize*10000)
textlines = Occurs(CHR(13),Textfield)+1
Prefixlines = FLOOR((totallines-textlines)/2)

Bye, Olaf.
 
In the picture below is the report shown in designer
237863e8-3d8f-4bd4-aa20-4549b27edd85.jpg

and in the next picture is the desired result.
1f70c7e4-2216-417d-8a49-6c627c9143b7.jpg


The field bb is a memo field with variable length and set as stretched with overflow.
The goal is to center vertically with bb the other two fields, ii and aa.

First I defined two report variables.
text_height will store the actual height of the bb field for the current row, while text_top the top position.
Actually, only text_height is necessary, but for the beauty I defined also text_top.
0ace0921-9671-4b59-8860-c73e7ed8ab26.jpg


In the bb field properties, I choose the Other tab, and then I clicked The Edit settings from Run-time extensions.
I typed in the Execute when textbox
Render
and in the edit box above
text_height=tp5
text_top=tp3
8efa1e71-aced-43b3-a061-1d7709735d3a.jpg


Both in the aa and ii field properties, I choose the Other tab, and then I clicked The Edit settings from Run-time extensions.
I typed in the Execute when textbox
Render
and in the edit box above
if text_height-tp5>0
tp3=text_top+floor((text_height-tp5)/2)
endif
640f0141-93d5-4223-a665-09644a6567bf.jpg


One problem was that ii and aa was rendered before bb, so text_height and text_top was the one from the previous row.
I simply cut the fields ii and aa (copy-cut) and then I pasted them back, and so in the frx they appear after bb and consequently was rendered after bb.

The test prg:
Code:
SET REPORTBEHAVIOR 90
CREATE CURSOR aa (ii I AUTOINC,aa C(10),bb M)
INSERT INTO aa (aa,bb) VALUES ('test 1','')
INSERT INTO aa (aa,bb) VALUES ('test 2','Short')
TEXT TO m.lcS
Lorem ipsum bibendum aenean lobortis semper a augue eget varius suspendisse quam pretium aenean vestibulum eu interdum faucibus habitasse senectus, eget nibh habitant sodales augue nam fusce quisque, semper proin viverra scelerisque quam tristique tincidunt hendrerit facilisis rutrum bibendum class nam, fusce maecenas interdum tempus lacus, ad aliquam aenean urna fusce enim pulvinar vulputate mattis porta nisi fringilla lectus.
ENDTEXT
INSERT INTO aa (aa,bb) VALUES ('test 3',m.lcS)
TEXT TO m.lcS
Dui non commodo phasellus cras nam mollis a, litora pulvinar curae sit lacus nam aliquam curabitur, volutpat convallis faucibus condimentum mollis cras phasellus id curae diam velit nisi potenti a, tortor varius porta nam eleifend duis justo, curabitur tortor phasellus dictumst ligula sapien.
ENDTEXT
INSERT INTO aa (aa,bb) VALUES ('test 3',m.lcS)
INSERT INTO aa (aa,bb) VALUES ('test 2','Second short')
REPORT FORM bb PREVIEW


My respects,
Vilhelm-Ion Praisach
Resita, Romania
 
@Olaf, prior to my last post I missed yours. It's exactly describing the situation.
The post thereafter might be the solution. I'll check with that and wil report back here.

@Vilhelm-Ion, I should dig in in yr solution. Disadvantage for me at firts glance is that I'm still not using th ereportlistener. But the solution Olaf gave me seems more easy and usefull for the oldfashioned way I use to do these output for labels. If I found some time to go ahead with th ereportlistener I certainly wil reminder your solution.

Thanks for again sharing your knowledge!!
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top