Results 1 to 3 of 3

Thread: How to print the contents of a Richtextbox and a normal textbox on one page?

Hybrid View

  1. #1
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: How to print the contents of a Richtextbox and a normal textbox on one page?

    simple printing example: combine this + ms example, you'll have what you want:


    Imports System.Drawing.Printing
    Public Class PrintTest
    Inherits System.Windows.Forms.Form

    Private Sub cmdPrint_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles cmdPrint.Click

    ' Create the document and attach an event handler.
    Dim MyDoc As New PrintDocument()
    AddHandler MyDoc.PrintPage, AddressOf MyDoc_PrintPage

    ' Allow the user to choose a printer and specify other settings.
    Dim dlgSettings As New PrintDialog()
    dlgSettings.Document = MyDoc
    Dim Result As DialogResult = dlgSettings.ShowDialog()

    ' If the user clicked OK, print the document.
    If Result = DialogResult.OK Then
    ' This method returns immediately, before the print job starts.
    ' The PrintPage event will fire asynchronously.
    MyDoc.Print()
    End If

    End Sub

    Private Sub MyDoc_PrintPage(ByVal sender As Object, _
    ByVal e As PrintPageEventArgs)


    ' Define the font.
    Dim MyFont As New Font("Arial", 30)

    ' Determine the position on the page.
    ' In this case, we read the margin settings
    ' (although there is nothing that prevents your code
    ' from going outside the margin bounds.)
    Dim x As Single = e.MarginBounds.Left
    Dim y As Single = e.MarginBounds.Top

    ' Determine the height of a line (based on the font used).
    Dim LineHeight As Single = MyFont.GetHeight(e.Graphics)

    ' Print five lines of text.
    Dim i As Integer
    For i = 0 To 4
    ' Draw the text with a black brush,
    ' using the font and coordinates we have determined.
    e.Graphics.DrawString("This is line " & i.ToString(), MyFont, Brushes.Black, x, y)

    ' Move down the equivalent spacing of one line.
    y += LineHeight
    Next
    y += LineHeight

    ' Draw an image.
    e.Graphics.DrawImage(Image.FromFile(Application.StartupPath & "\test.bmp"), x, y)

    End Sub


    End Class

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2007
    Location
    Arnhem, the Netherlands
    Posts
    5

    Re: How to print the contents of a Richtextbox and a normal textbox on one page?

    Thanks .Paul., I'll try this.
    I'm not too familiar yet with these handler things and so, but your code looks OK.

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