|
|||||||
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 07
Location: Arnhem, the Netherlands
Posts: 5
![]() |
How to print the contents of a Richtextbox and a normal textbox on one page?
Hi all,
I know how to print the contents of a Richtextbox (see the RichTextBoxPrintCtrl control, http://support.microsoft.com/kb/811401), but on this way the contents of the Richtextbox is treated as one completed document, in other words, after the contents has been printed, the page is ejected from the printer. Even if the Richtextbox contains only one line of text or only one small picture, the page is ejected. I want to print the contents of a Richtextbox, followed by some regular text (e.g. from a normal textbox), on one page. Or: Print first regular text, then a Richtextbox, then regular text, then a Richtextbox on one page. Anyone know how to do this? I'm programming in VB.NET, 2005. Help is greatly appreciated. Thanks in advance. |
|
|
|
|
|
#2 |
|
PowerPoster
Join Date: May 07
Location: Chelmsford UK
Posts: 6,080
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 07
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. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|