Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
» Regular Expr Tester
» Free Tools

How to Print a Multiline TextBox with Alignment!

Total Hit ( 4179)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article



API Declarations

Click here to copy the following block
'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


Click here to copy the following block
'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

Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with, SQL Server and other MS technologies. He is, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )

Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.