borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincani
:: ...How to Print a Multiline TextBox with Alignment!

Author  

Grant C. Schuleman

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

'Add this to your Declarations Section:
Public Declare Function SetTextAlign Lib "gdi32.dll" (ByVal hdc As Long, ByVal wFlags As Long) As Long
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wmsg As Long, ByVal wparam As Long, lparam As Any) As Long
Public Const TA_CENTER = 6

Usage

'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

:: Navigation

Home

Printing Using Visual Basic

Previous Tip

Next Tip

:: Search this site
Google
:: Sponsored Links



Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder