print7

 

Print Text With Specific Alignment


Print Text With Specific Alignment


Preparations

Add 1 Command Button to your form.


Form Code


Public Sub PrintAlignedText(s As String, Alignment As String)
Select Case Alignment
Case "Center"
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(s)) \ 2
Case "Left"
Printer.CurrentX = 0
Case "Right"
Printer.CurrentX = Printer.ScaleWidth - Printer.TextWidth(s)
End Select
Printer.Print s
' use the EndDoc command if this text is the last thing you want
' to print on the paper
Printer.EndDoc
End Sub

Private Sub Command1_Click()
' replace the "hello" with the text you want to print.
' replace the "Center" with your desirable alignment
' ("Center", "Left" or "Right")
Call PrintAlignedText("hello", "Center")
End Sub