Print Preview ActiveX Active Users: 69 / Visits Today: 8
Highest Active Users: 138
Print Preview ActiveX
Home | Profile | Register | Active Topics | Members | Search | FAQ | RSS
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Print Preview
 Tips & Tricks
 VB Routine: paraTextFit
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic: VB Routine: getNumLines Topic Next Topic: VB Routine: paraTextHeight  

wbgookin
Junior Member

USA
113 Posts

Posted - 11/20/2004 :  02:33:52  Show Profile  Visit wbgookin's Homepage  Reply with Quote
Here's a routine I use to fit a paraText to a specified area. It uses the paraTextHeight routine I posted to calculate the height, and then shrinks the font if the text is too big. It only reduces, but changing it to enlarge wouldn't be too hard. Anyway, it works for me, but your mileage may vary!


Public Sub paraTextFit(prn As PrintPreview5.Preview, paraString As String, xPos As Variant, yPos As Variant, paraWidth As Variant, paraHeight As Variant)
    'Variables:
    'prn is the previously defined preview control
    'paraString is the string you want to send to paraText
    'xPos is the x position that you want to send to paraText
    'yPos is the y position that you want to send to paraText
    'paraWidth is the width you want to send to paraText
    'paraHeight is the height you want to send to paraText
    
    'startSize is the initial font size
    'stepSize is the amount to shift the font
    Dim startSize As Integer
    Dim stepSize As Integer

    'Set the initial values
    startSize = prn.FontSize
    stepSize = 0

    'Loop through, comparing the height of the paraText to the desired height.
    'If it is too high, reduce the font size and try again.
    'Limit to a font size of 1, or it will get messed up.
    Do While (paraTextHeight(prn, paraString, paraWidth) > prn.C_Twips(paraHeight)) And stepSize < startSize - 1
        stepSize = stepSize + 1
        prn.FontSize = startSize - stepSize
    Loop

    'Now, the font is okay (or as close to it as possible, with a size=1).
    'Print the paratext at the currentX and currentY values
    prn.ParaText paraString, xPos, yPos, paraWidth

    'Set the font size back to the beginning size
    prn.FontSize = startSize
End Sub
Go to Bottom of Page
  Previous Topic: VB Routine: getNumLines Topic Next Topic: VB Routine: paraTextHeight  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Print Preview ActiveX © Mandix Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000 Version 3.4.02