'Create a Form with a Command Button and a Multiline
Textbox
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim ta As Long
Dim TextLines As Long
Dim TextBuff As String
Dim CharRet As Long
'Add this
to your print code!' Center text on printer object
ta = SetTextAlign(Printer.hdc, TA_CENTER)
Printer.CurrentY = (Printer.ScaleHeight / .Parent.ScaleHeight) * .Top
' Get
number of lines in text box
TextLines = SendMessage(.hwnd, &HBA, 0, 0)
' Extract
& print each line in TextBox
For i = 0 To TextLines - 1
TextBuff = Space(1000)
Printer.CurrentX = (Printer.ScaleWidth /
.Parent.ScaleWidth) * (.Left + (.Width / 2))
' Setup buffer for the line!
Mid(TextBuff, 1, 1) = Chr(79 And &HFF)
Mid(TextBuff, 2, 1) = Chr(79 \ &H100)
CharRet = SendMessage(.hwnd, &HC4, i, ByVal
TextBuff)
Printer.Print Left(TextBuff, CharRet)
Next i
' Reset
alignment back to original setting
ta = SetTextAlign(Printer.hdc, ta)
End Sub |