473,883 Members | 1,705 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 14100
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
8702
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
7778
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
3418
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
1347
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
8730
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
11788
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
1000
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
5490
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
11144
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
11123
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...
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
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
9567
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...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5794
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
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

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.