CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    Printing a text Box

    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


  2. #2
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: Printing a text Box

    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.


  3. #3
    Join Date
    Dec 2007
    Posts
    3

    Cool Re: Printing a text Box

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Printing a text Box

    Then it is a different question. Please start a new thread.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Printing a text Box

    I think I did that before:
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured