Click to See Complete Forum and Search --> : Printing a text Box


March 6th, 2000, 06:45 AM
I have a text box in my application, and want to print it. I use the CommonDialog to get the informations about the printer. But how can I send the Text to the printer.
Can anyone tell how to do this.

mfG Florian

TH1
March 6th, 2000, 07:24 AM
If all you want is to print the contents of the textbox then just do the following.

Printer.print text1.text
printer.enddoc



This will send what text is in the textbox to the default printer.
Hope this helps.

tllocke
January 17th, 2008, 05:00 PM
This is the exact question I came here to find, and the above solution did work oh so easily. However, the text in my texbox is large, and when it prints, it doesn't recognize the carriage returns and most of the paragraphs are cut off. Anyone know a way around this?

dglienna
January 17th, 2008, 05:19 PM
Then it is a different question. Please start a new thread.

WoF
January 17th, 2008, 07:21 PM
I think I did that before:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any _
) As Long

Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB

Private Function GetTextBoxLine(TBox As TextBox, ByVal LineNr As Long) As String
' get one line out of a textbox
Dim LineLength As Long
Dim LineStart As Long

'get start of line and length
LineStart = SendMessage(TBox.hWnd, EM_LINEINDEX, LineNr, ByVal 0&)
LineLength = SendMessage(TBox.hWnd, EM_LINELENGTH, LineStart, ByVal 0&)

'return line
GetTextBoxLine = Mid$(TBox, LineStart + 1, LineLength)
End Function

Private Sub PrintTextBox(TBox As TextBox)
Dim nLines%, i%

nLines = SendMessage(TBox.hWnd, EM_GETLINECOUNT, 0, 0&)
For i = 0 To nLines - 1
Printer.Print GetTextBoxLine(TBox, i)
Next