Option Explicit
Private BaseY As Double
Public Sub [B]PrintMyForm[/B](MyForm As Form)
Dim Obj As Object
Dim Factor As Double
Dim FormScaleMode As Integer
FormScaleMode = MyForm.ScaleMode
MyForm.ScaleMode = vbTwips
Printer.ScaleMode = vbTwips
Factor = Printer.Height / Printer.Width
Printer.Scale (0, 0)-(MyForm.Width, MyForm.Width * Factor)
BaseY = (Printer.ScaleHeight - MyForm.Height) / 2
For Each Obj In MyForm
If Obj.Visible Then
PrintObject Obj
End If
Next Obj
MyForm.ScaleMode = FormScaleMode
Printer.EndDoc
End Sub
Public Sub PrintObject(Obj As Object)
If TypeOf Obj Is Line Then
PrinMyLine Obj
ElseIf TypeOf Obj Is TextBox Then
PrinTxt Obj
ElseIf TypeOf Obj Is Label Then
PrinLbl Obj
ElseIf TypeOf Obj Is PictureBox Then
PrintPicture Obj
ElseIf TypeOf Obj Is Image Then
PrintImage Obj
End If
End Sub
Public Sub PrinTxt(Txt As TextBox)
With Txt
Printer.ForeColor = .ForeColor
Printer.Font = .Font
Printer.Font.Name = .Font.Name
Printer.Font.Charset = .Font.Charset
Printer.Font.Bold = .Font.Bold
Printer.Font.Italic = .Font.Italic
Printer.Font.Size = .Font.Size
Printer.Font.Strikethrough = .Font.Strikethrough
Printer.Font.Underline = .Font.Underline
Printer.Font.Weight = .Font.Weight
Select Case .Alignment
Case vbCenter
Printer.CurrentX = .Left + (.Width - Printer.TextWidth(.Text)) / 2
Case vbLeftJustify
Printer.CurrentX = .Left
Case vbRightJustify
Printer.CurrentX = .Left + .Width - Printer.TextWidth(.Text)
End Select
Printer.CurrentY = BaseY + .Top
Printer.Print .Text
End With
End Sub
Public Sub PrinLbl(Lbl As Label)
With Lbl
Printer.ForeColor = .ForeColor
Printer.FontTransparent = (.BackStyle = 0)
Set Printer.Font = Lbl.Font
Printer.Font.Name = Lbl.Font.Name
Printer.Font.Charset = .Font.Charset
Printer.Font.Bold = .Font.Bold
Printer.Font.Italic = .Font.Italic
Printer.Font.Size = .Font.Size
Printer.Font.Strikethrough = .Font.Strikethrough
Printer.Font.Underline = .Font.Underline
Printer.Font.Weight = .Font.Weight
Select Case .Alignment
Case vbCenter
Printer.CurrentX = .Left + (.Width - Printer.TextWidth(.Caption)) / 2
Case vbLeftJustify
Printer.CurrentX = .Left
Case vbRightJustify
Printer.CurrentX = .Left + .Width - Printer.TextWidth(.Caption)
End Select
Printer.CurrentY = BaseY + .Top
Printer.Print .Caption
End With
End Sub
Public Sub PrintPicture(Pic As PictureBox)
With Pic
Printer.PaintPicture .Image, .Left, BaseY + .Top, .Width, .Height
End With
End Sub
Public Sub PrintImage(Img As Image)
With Img
Printer.PaintPicture .Picture, .Left, BaseY + .Top, .Width, .Height
End With
End Sub
Public Sub PrinMyLine(MyLine As Line, Optional DrawWidth As Integer = 10)
With MyLine
Printer.DrawWidth = DrawWidth
Printer.Line (.X1, BaseY + .Y1)-(.X2, BaseY + .Y2)
End With
End Sub