Print Preview ActiveX Active Users: 48 / Visits Today: 72
Highest Active Users: 48
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: paraTextHeight
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic: VB Routine: paraTextFit Topic Next Topic: VB Routine:  boxedTextAt  

wbgookin
Junior Member

USA
113 Posts

Posted - 11/20/2004 :  02:31:47  Show Profile  Visit wbgookin's Homepage  Reply with Quote
Here's a routine I use to calculate how high a "paraText" will be before I actually print it to the page. It works for me, but your mileage may vary.


Public Function paraTextHeight(prn As PrintPreview5.Preview, paraString As String, paraWidth As Variant) As Long
    'Variables:
    'prn is the previously defined preview control
    'paraString is the string you want to send to paraText
    'paraWidth is the width string you want to send to paraText (e.g., "1.2 in")
    'Returns:
    'The paraText height as a LONG, based on the given paraWidth.
    
    'Initialize the paraTextHeight value for return
    paraTextHeight = 0
    
    'The startX and startY variables are to reset the currentX and currentY values when we're done
    'The startFrame is the frame we have set as the current frame
    Dim startX As Long
    Dim startY As Long
    Dim startFrame As String
    
    'startFontName and startFontSize are the font information we are starting with
    'we have to reset them with the new frame
    Dim startFontName As String
    Dim startFontSize As Integer
    
    'The initY and finalY variables will be used to calculate the required height of the paraText
    Dim initY As Long
    Dim finalY As Long
    
    'Set the startX and startY variables
    startX = prn.CurrentX
    startY = prn.CurrentY
    
    'Set the startframe = currentFrame, and the startFont = current fontsize
    startFrame = prn.CurrentFrame
    startFontSize = prn.FontSize
    startFontName = prn.FontName
    
    'Set the current frame to "junkframe"
    prn.AddFrame "junkframe", 0, 0, prn.PageWidth, prn.PageHeight
    prn.CurrentFrame = "junkframe"
    prn.FontName = startFontName
    prn.FontSize = startFontSize
    
    'Set the initial Y value variable
    initY = prn.CurrentY
    
    'Print the paraText
    prn.ParaText paraString, , , paraWidth
    
    'Set the final Y value variable
    finalY = prn.CurrentY
    
    'Calculate the required height for the paraText
    paraTextHeight = finalY - initY
    
    'Clear the "junkframe" so our printing doesn't show
    prn.ClearFrame
    
    'Set the frame back to the original frame we were in
    prn.CurrentFrame = startFrame
    
    'Set the currentX and currentY back to what they were at the start
    prn.CurrentX = startX
    prn.CurrentY = startY
    prn.FontName = startFontName
    prn.FontSize = startFontSize
    
End Function
Go to Bottom of Page
  Previous Topic: VB Routine: paraTextFit Topic Next Topic: VB Routine:  boxedTextAt  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
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