473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Print the RichTextBox

Hi,

I use the RichTextBox in my program.
It will use different language in this RichTextBox (chinese and english
characters), and it set the "DualFont" and use different fonts.
By the way, how can I print out this content to printer easily?

Thanks!

James
Sep 13 '06 #1
9 4818
PS. Print the content with the same format of RichTextBox.
"James Wong" <cp*******@nospam.nospam¼¶¼g©ó¶l¥ó·s»D:Oh********* *****@TK2MSFTNGP03.phx.gbl...
Hi,

I use the RichTextBox in my program.
It will use different language in this RichTextBox (chinese and english
characters), and it set the "DualFont" and use different fonts.
By the way, how can I print out this content to printer easily?

Thanks!

James

Sep 13 '06 #2
"James Wong" <cp*******@nospam.nospamschrieb:
I use the RichTextBox in my program.
By the way, how can I print out this content to printer easily?
HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
..NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;811401>

Getting WYSIWYG Print Results from a .NET RichTextBox
<URL:http://msdn.microsoft.com/library/en-us/dnwinforms/html/wnf_RichTextBox.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 13 '06 #3
Hi,

I solve this problem.
thank you for your solution~

James
"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
???????:OG**************@TK2MSFTNGP05.phx.gbl...
"James Wong" <cp*******@nospam.nospamschrieb:
>I use the RichTextBox in my program.
By the way, how can I print out this content to printer easily?

HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
.NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;811401>

Getting WYSIWYG Print Results from a .NET RichTextBox
<URL:http://msdn.microsoft.com/library/en-us/dnwinforms/html/wnf_RichTextBox.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 14 '06 #4
Hi,

I have another questions for the RichTextBox.

1) How can i get the height & width of content in this RichTextBox with font
format?
2) Can I set the position layout of RichTextBox in paper?

Thanks!

James

"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
???????:OG**************@TK2MSFTNGP05.phx.gbl...
"James Wong" <cp*******@nospam.nospamschrieb:
>I use the RichTextBox in my program.
By the way, how can I print out this content to printer easily?

HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
.NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;811401>

Getting WYSIWYG Print Results from a .NET RichTextBox
<URL:http://msdn.microsoft.com/library/en-us/dnwinforms/html/wnf_RichTextBox.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 14 '06 #5
Hi James,
>1) How can i get the height & width of content in this RichTextBox with
font format?

RichTextBox has a ContentsResized event, which will bring us the new
requested size in its event args. Is it what you need?
>2) Can I set the position layout of RichTextBox in paper?
I'm sorry that I couldn't understand what you mean. Could you please
explain more?

I look forward to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 14 '06 #6
Hi Linda,

I use the DualFont function in RichTextBox, but it seems not work.

example 1:
RichTextBoxPrintCtrl1.LanguageOption = RichTextBoxLanguageOptions.DualFont
RichTextBoxPrintCtrl1.Text = "{some chinese characters} ABCDEF"
RichTextBoxPrintCtrl1.Font = New Font("{chinese font}", 12)
RichTextBoxPrintCtrl1.Font = New Font("Gill Sans Ultra Bold", 40)

It occurs two fonts ("{chinese font}" & "Gill Sans Ultra Bold"), but the
font size is 40.
-----------------------------------------------------------------------------------------------------------

example 2:
RichTextBoxPrintCtrl1.LanguageOption = RichTextBoxLanguageOptions.DualFont
RichTextBoxPrintCtrl1.Text = "{some chinese characters} ABCDEF"
RichTextBoxPrintCtrl1.Font = New Font("Gill Sans Ultra Bold", 40)
RichTextBoxPrintCtrl1.Font = New Font("{chinese font}", 12)

It occurs one font only ("{chinese font}"), but the font size is 12.
-----------------------------------------------------------------------------------------------------------

Furthermore, I read this article. (
http://support.microsoft.com/?scid=kb;EN-US;811401 )
If my project has many RichTextBox, can I print these contents in one paper?

By the way, how can I set the coordinates of print out paper using
RichTextBox?
e.g. adjust to center, adjust 2 cm in left side...

Thanks~

James
"Linda Liu [MSFT]" <v-****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:P4******** ******@TK2MSFTNGXA01.phx.gbl...
Hi James,
>>1) How can i get the height & width of content in this RichTextBox with
font format?

RichTextBox has a ContentsResized event, which will bring us the new
requested size in its event args. Is it what you need?
>>2) Can I set the position layout of RichTextBox in paper?

I'm sorry that I couldn't understand what you mean. Could you please
explain more?

I look forward to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 15 '06 #7
Hi James,

This is a quick note to let you know that I am researching on this issue
and will get it back to you ASAP.

I appreciate your patience.
Sincerely,
Linda Liu
Microsoft Online Community Support
Sep 15 '06 #8
Hi James,

Sorry for my delayed reply.

The LanguageOption property of RichTextBox is new in .NET 2.0. This
property gets or sets a value that indicates RichTextBox settings for Input
Method Editor (IME) and Asian language support. The default value of the
LanguageOption property of RichTextBox is AutoFont|DualFont. That's to say,
RichTextBox supports DualFont by default.

When a richtextbox supports DualFont, it doesn't means that we could set an
English font for ASCII text and an Asian font for Asian text at one time.
Instead, we should make use of the SelectionFont property of the
richtextbox to set fonts for the two kinds of text respectively.

For example, we could add two buttons called button1 and button2 on the
form. Click button1 to set an English font for ASCII text and click button2
to set an Asian font for Asian text. To set the ASCII text in the
richtextbox to the English font, select the ASCII text in the richtextbox
and click button1. To set the Asian text in the richtextbox to the Asian
font, select the Asian text in the richtextbox and click button2.
If my project has many RichTextBox, can I print these contents in one
paper?

In the sample provided in the Microsoft support website, the actual
printing work is done by the SendMessage Win32 API, which is called in the
Print method in the RichTextBoxPrintCtrl class. This line of code is 'res =
SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);'. Note that the
richtextboxctrl control's Handle is passed to the SendMessage function.
This means that we could only print out the content in ONE richtextboxctrl
control at one time.

To print out the contents in several richtextboxctrls at one time in one
paper, we could copy the contents in all the richtextboxctrls into one
richtextboxctrl and print the total content out and restore the content in
the richtextboxctrl after the printing is finished. Suppose there're two
richtextboxctrls on the form. The following is a sample to print out
contents in both richtextboxctrls at one time.

void printDocument1_BeginPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
this.richTextBoxPrintCtrl2.SelectAll();
this.richTextBoxPrintCtrl2.Copy();

this.richTextBoxPrintCtrl1.Focus();
this.richTextBoxPrintCtrl1.SelectionStart =
this.richTextBoxPrintCtrl2.TextLength;
this.richTextBoxPrintCtrl1.Paste();

checkPrint = 0;
}

void printDocument1_EndPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
this.richTextBoxPrintCtrl1.Undo();
}
how can I set the coordinates of print out paper using RichTextBox? e.g.
adjust to center, adjust 2 cm in left side...

You could make use of the DefaultPageSettings property of PrintDocument to
set the page margin. The following is a sample.

this.printDocument1.DefaultPageSettings.Margins.Le ft = 200;

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Sep 19 '06 #9
Hi Linda,

thanks for the reply

James

"Linda Liu [MSFT]" <v-****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:39******** ******@TK2MSFTNGXA01.phx.gbl...
Hi James,

Sorry for my delayed reply.

The LanguageOption property of RichTextBox is new in .NET 2.0. This
property gets or sets a value that indicates RichTextBox settings for
Input
Method Editor (IME) and Asian language support. The default value of the
LanguageOption property of RichTextBox is AutoFont|DualFont. That's to
say,
RichTextBox supports DualFont by default.

When a richtextbox supports DualFont, it doesn't means that we could set
an
English font for ASCII text and an Asian font for Asian text at one time.
Instead, we should make use of the SelectionFont property of the
richtextbox to set fonts for the two kinds of text respectively.

For example, we could add two buttons called button1 and button2 on the
form. Click button1 to set an English font for ASCII text and click
button2
to set an Asian font for Asian text. To set the ASCII text in the
richtextbox to the English font, select the ASCII text in the richtextbox
and click button1. To set the Asian text in the richtextbox to the Asian
font, select the Asian text in the richtextbox and click button2.
>If my project has many RichTextBox, can I print these contents in one
paper?

In the sample provided in the Microsoft support website, the actual
printing work is done by the SendMessage Win32 API, which is called in the
Print method in the RichTextBoxPrintCtrl class. This line of code is 'res
=
SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);'. Note that the
richtextboxctrl control's Handle is passed to the SendMessage function.
This means that we could only print out the content in ONE richtextboxctrl
control at one time.

To print out the contents in several richtextboxctrls at one time in one
paper, we could copy the contents in all the richtextboxctrls into one
richtextboxctrl and print the total content out and restore the content in
the richtextboxctrl after the printing is finished. Suppose there're two
richtextboxctrls on the form. The following is a sample to print out
contents in both richtextboxctrls at one time.

void printDocument1_BeginPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
this.richTextBoxPrintCtrl2.SelectAll();
this.richTextBoxPrintCtrl2.Copy();

this.richTextBoxPrintCtrl1.Focus();
this.richTextBoxPrintCtrl1.SelectionStart =
this.richTextBoxPrintCtrl2.TextLength;
this.richTextBoxPrintCtrl1.Paste();

checkPrint = 0;
}

void printDocument1_EndPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
this.richTextBoxPrintCtrl1.Undo();
}
>how can I set the coordinates of print out paper using RichTextBox? e.g.
adjust to center, adjust 2 cm in left side...

You could make use of the DefaultPageSettings property of PrintDocument to
set the page margin. The following is a sample.

this.printDocument1.DefaultPageSettings.Margins.Le ft = 200;

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support


Sep 19 '06 #10

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

Similar topics

1
by: Tim | last post by:
Hi, I have created a print routing that works great for plain text. I have some text in Rich Text format that I would like to print as it appears with its formatting. Does anyone know how to...
16
by: Neal | last post by:
Hi, I saw the VB6 Code to do this at this link: http://www.dotnet247.com/247reference/msgs/11/56581.aspx The VB6 Code reads as follows: Private Type Rect Left As Long
2
by: SamSpade | last post by:
I have a RichTextBox and I want to print the contents. I have some code that I downloaded but it requires a Font and uses Drawstring. Doesn't sound right since RTF could contain many different...
2
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to...
4
by: Cc | last post by:
how to print content of richtextbox?
2
by: PJO | last post by:
I've got a Print menu item on a parent navigation form. How can I get it to print the contents of a RichTextBox located on a child form? TIA -Pat
3
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...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
3
by: kaushalgajjar | last post by:
Hi, I am into a trouble since 1 week and unable to find the solution from any community or site. I have created a small program that i want to print along with horizontal lines (like a notebook...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.