Hi these links should help,
the first one has a nice working example, but it's C sharp, the second one does the same thing in VB, but no example
http://www.codeguru.com/Csharp/Cshar...icle.php/c4781 http://msdn.microsoft.com/library/de...ichTextBox.asp
hth Greetz Peter
--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
"ng" <t_*****@yahoo.com> schreef in bericht news:6l******************@bignews5.bellsouth.net.. .
Peter,
I found this very helpful, and interesting! But I have another problem - I can't figure out how to send formatted text from a richtextbox.rtf to the printer without getting the formatting codes printed. I remember when sending columnar data to a printer was so easy! And Microsoft documentation seems to be silent on this. Go figure!
Thanks for whatever you can offer.
T
Peter Proost wrote:
hi this should help,
make a new class, call it TextPrint and then copy paste this:
'to actualy print something use this:
'Dim x As New TextPrint("my text")
'x.Print()
Imports System.Windows.Forms
Imports System.Drawing
Public Class TextPrint
Inherits Printing.PrintDocument
Private fntPrintFont As Font
Private strText As String
Public Sub New(ByVal Text As String)
MyBase.New()
strText = Text
End Sub
Public Property Text() As String
Get
Return strText
End Get
Set(ByVal Value As String)
strText = Value
End Set
End Property
Protected Overrides Sub OnBeginPrint(ByVal ev _
As Printing.PrintEventArgs)
MyBase.OnBeginPrint(ev)
If fntPrintFont Is Nothing Then
fntPrintFont = New Font("Times New Roman", 12)
End If
End Sub
Public Property Font() As Font
Get
Return fntPrintFont
End Get
Set(ByVal Value As Font)
fntPrintFont = Value
End Set
End Property
Protected Overrides Sub OnPrintPage(ByVal ev _
As Printing.PrintPageEventArgs)
MyBase.OnPrintPage(ev)
Static intCurrentChar As Integer
Dim intPrintAreaHeight, intPrintAreaWidth, _
intMarginLeft, intMarginTop As Integer
With MyBase.DefaultPageSettings
intPrintAreaHeight = .PaperSize.Height - _
.Margins.Top - .Margins.Bottom
intPrintAreaWidth = .PaperSize.Width - _
.Margins.Left - .Margins.Right
intMarginLeft = .Margins.Left 'X
intMarginTop = .Margins.Top 'Y
End With
If MyBase.DefaultPageSettings.Landscape Then
Dim intTemp As Integer
intTemp = intPrintAreaHeight
intPrintAreaHeight = intPrintAreaWidth
intPrintAreaWidth = intTemp
End If
Dim intLineCount As Int32 = _
CInt(intPrintAreaHeight / Font.Height)
Dim rectPrintingArea As New RectangleF(intMarginLeft, _
intMarginTop, intPrintAreaWidth, intPrintAreaHeight)
Dim objSF As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
ev.Graphics.MeasureString(Mid(strText, _
UpgradeZeros(intCurrentChar)), Font, _
New SizeF(intPrintAreaWidth, _
intPrintAreaHeight), objSF, _
intCharsFitted, intLinesFilled)
ev.Graphics.DrawString(Mid(strText, _
UpgradeZeros(intCurrentChar)), Font, _
Brushes.Black, rectPrintingArea, objSF)
intCurrentChar += intCharsFitted
If intCurrentChar < strText.Length Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
intCurrentChar = 0
End If
End Sub
Public Function UpgradeZeros(ByVal Input As Integer) As Integer
If Input = 0 Then
Return 1
Else
Return Input
End If
End Function
End Class
hth Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"iwdu15" <iw****@discussions.microsoft.com> schreef in bericht
news:02**********************************@microsof t.com...
can anybody help me print from a rich text box? i tried the way they
showed
on the MSDN web page, but it did not work. I am using VB.net 2003...any
help
would be appreciated