|
-
May 26th, 2007, 09:04 AM
#2
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|