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******** **********@bign ews5.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.PrintD ocument
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(By Val ev _
As Printing.PrintE ventArgs)
MyBase.OnBeginP rint(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(ByV al ev _
As Printing.PrintP ageEventArgs)
MyBase.OnPrintP age(ev)
Static intCurrentChar As Integer
Dim intPrintAreaHei ght, intPrintAreaWid th, _
intMarginLeft, intMarginTop As Integer
With MyBase.DefaultP ageSettings
intPrintAreaHei ght = .PaperSize.Heig ht - _
.Margins.Top - .Margins.Bottom
intPrintAreaWid th = .PaperSize.Widt h - _
.Margins.Left - .Margins.Right
intMarginLeft = .Margins.Left 'X
intMarginTop = .Margins.Top 'Y
End With
If MyBase.DefaultP ageSettings.Lan dscape Then
Dim intTemp As Integer
intTemp = intPrintAreaHei ght
intPrintAreaHei ght = intPrintAreaWid th
intPrintAreaWid th = intTemp
End If
Dim intLineCount As Int32 = _
CInt(intPrintAr eaHeight / Font.Height)
Dim rectPrintingAre a As New RectangleF(intM arginLeft, _
intMarginTop, intPrintAreaWid th, intPrintAreaHei ght)
Dim objSF As New StringFormat(St ringFormatFlags .LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
ev.Graphics.Mea sureString(Mid( strText, _
UpgradeZeros(in tCurrentChar)), Font, _
New SizeF(intPrintA reaWidth, _
intPrintAreaHei ght), objSF, _
intCharsFitted, intLinesFilled)
ev.Graphics.Dra wString(Mid(str Text, _
UpgradeZeros(in tCurrentChar)), Font, _
Brushes.Black, rectPrintingAre a, objSF)
intCurrentChar += intCharsFitted
If intCurrentChar < strText.Length Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
intCurrentChar = 0
End If
End Sub
Public Function UpgradeZeros(By Val 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****@discuss ions.microsoft. com> schreef in bericht
news:02******** *************** ***********@mic rosoft.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