Print Preview ActiveX Active Users: 21 / Visits Today: 68
Highest Active Users: 21
Print Preview ActiveX
Home | Profile | Register | Active Topics | Members | Search | FAQ | RSS
 All Forums
 Print Preview
 Tips & Tricks
 VB Code Snippet: fit plain text in area

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert Email Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert a File

Check here to subscribe to this topic.
   

T O P I C    R E V I E W
wbgookin Posted - 11/20/2004 : 02:50:19
My code fitting routine is too complicated to explain quickly (naturally it's not terribly well documented, but it will do horizontal or vertical text), but the basics of it are below. It uses the getNumLines I posted here to calculate the required number of lines, and then iterates, shrinking the font if necessary. Then to print this, you use similar code that is in the getNumLines to loop through each word and print it.



'Based on the width allowed, get the number of lines
numberOfLines = getNumLines(prn, printText, fitWidth)

'If numberOfLines*lineheight is greater than the allowed height, we need to start shrinking the font
initFontSize = prn.FontSize
delta = 0
Do While numberOfLines * prn.TextHeight("A") >= prnHeight And delta < initFontSize
    delta = delta + 1
    prn.FontSize = initFontSize - delta
Loop

'We also need to check the width, in case a single word is greater than the available width
'Set the initial X just in case
For i = LBound(splitText) To UBound(splitText)
    Do While prn.TextWidth(Trim(splitText(i) & splitString)) >= prnWidth And delta < initFontSize
        delta = delta + 1
        prn.FontSize = initFontSize - delta
    Loop
Next i

Print Preview ActiveX © Mandix Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000 Version 3.4.02