• 0

[vb .net] printing textbox contents


Question

How the hell do I simply print out the contents of a textbox? First I tried a simple:

   Private Sub mnuMainFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMainFilePrint.Click
        Select Case printPad.ShowDialog()
            Case DialogResult.OK
                printdocPad.Print()
        End Select

    End Sub

    Private Sub printdocPad_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printdocPad.PrintPage
        e.Graphics.DrawString(noteArray(activePad).txtmain.Text, noteArray(activePad).txtmain.font, System.Drawing.Brushes.Black, 0, 0)
    End Sub

That wouldn't wrap text. So I figured out I needed to find the rectangle instead of just using points. I try this and still not wrapping and its printing if down and to the left, not right in the upper corner of the page:

   Private Sub mnuMainFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMainFilePrint.Click
        Select Case printPad.ShowDialog()
            Case DialogResult.OK
                printdocPad.Print()
        End Select

    End Sub

    Private Sub printdocPad_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printdocPad.PrintPage
        Dim layout_rect As RectangleF
        layout_rect = New RectangleF(0, 0, printdocPad.PrinterSettings.DefaultPageSettings.PaperSize.Width , printdocPad.PrinterSettings.DefaultPageSettings.PaperSize.Height)

        e.Graphics.DrawString(noteArray(activePad).txtmain.Text, noteArray(activePad).txtmain.font, System.Drawing.Brushes.Black, layout_rect)
    End Sub

I am completely lost right now and can not find any documentation to help me along. Can someone tell me what I'm doing so wrong?

Sorry bout so many questions lately, it's just I'm really damn stressed with life and obviously am not thinking clearly.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

ok well, I was shown some code I had previously seen but disregarded. I have to edit it a bit, but I'll use a temp file and stream from the file and then delete the file once I'm done. Thanks anyway.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.