473,761 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

printing from a rich text box

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
Nov 21 '05 #1
4 14080
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

Nov 21 '05 #2
ng
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******* *************** ************@mi crosoft.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


Nov 21 '05 #3
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




Nov 21 '05 #4
ng
Thank you, Peter. These are both very instructional. I'm learning C#
and VB.Net.

T
Peter Proost wrote:
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 <mailto: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****** *************** *************@m icrosoft.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


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8691
by: Alfredo Agosti | last post by:
Hi folks, I have an Access 2000 db with a memo field. Into the memo field I put text with bold attributes, URL etc etc What I need to to is converting the rich text contained into the memo field in plain text. That's because I truncate the string text but if, when I truncate it there's a rich tag the code following the truncated string is corrupted. Don't know if it's clear enough.
1
7767
by: PC User | last post by:
I found this Rich Text Editor and I've been trying to recreate it in my own application. I've had trouble with the COMCTL.ImageListCtrl and the COMCTL.Toolbar to recreate the toolbar. And I've had trouble with COMCTL.SBarCtrl in recreating the status bar. Does anyone have any experience with these or know of any website that explaines how to use these? http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=5545 ...
1
3414
by: Peter | last post by:
I have written a small terminal app that reads and writes to the serial port. In particular as the data is read from the serial port it is appended to the rich text box. The problem I am experiencing is this: When CrLf is received in the same read and appended to the rich text box, it processes it by moving to the beginning of the next line. This is right. When Cr is received at the end of one read it is appended to the rich text box....
4
1344
by: ng | last post by:
How in the world can I print a richtextbox rtf without including the special characters like crlf and the font definition and such? Microsoft documentation is silent on this. Thanks so much! T
3
8728
by: Stanley | last post by:
Hi all! I have trouble with printing rich text box that has multi fonts format. I have found some printing example in vb.net on web, but they can only print one font format!! I'm new to printing in vb.net. Please help me, thank in advance!
1
11763
by: tomi.trescak | last post by:
Hi I have a problem with storing rich text in MySQL. I store rich text in MySQL (in column with type "text") which i get from Rich Textbox control. When i do reverse processing by trying to fill rich text back to rich techbox (i set correct property "Rtf") i get whole text like: { tf1ansiansicpg1250deff0deflang1029{fonttbl{f0fnilfcharset0
0
996
by: Howard | last post by:
In VB6 this is easy, One method of the RTB does it. I use this to teach first year students how to make a simple word processor Now I have to migrate to vb 2005 express. The RTB here does not seem to have this functionality How do you send the contents of a rich text box to the printer now? The only code I've seen so far is far too complicated.
4
5483
by: Neil | last post by:
Just found out that the Microsoft Rich Textbox does not support full text justification, since it's based on Version 1.0 of the RichEdit Window Class, and full text justification is only available in versions 3.0 or later of the class. However, also just found out that the new Rich Text property in Access 2007 ALSO does not support full text justification! This seems incredible, that MS would create a brand new application, and not...
16
11134
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might know one way or the other whether that was true or not, or could point me to an article or help text that would. What I have seen so far online and in Access 2007 help seems to confirm the above. But that (or at least (b)) seems incredible that it...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.