Click here to Skip to main content
15,919,423 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Please Tell Me How to set richtextbox into A4 size
Updated 7-Sep-17 11:47am
Sandeep Mewara 16-May-11 2:52am    

Maybe this discussion[^] can help you.
Share this answer
There's no such thing in the RichTextBox.

The paper size and orientation are strictly printing concepts that have nothing to do with the RTB itself. The only time this would apply is when your code goes to print the content of the RTB. These settings are not settable in the RTB document, but in your printing code.

If your code isn't doing the printing, that has to be left up to the application that does do the printing. This is something your code has no control over in another application.
Share this answer
Craig P Williams Sr 7-Sep-17 14:51pm    
This is incorrect. RTF page standard settings are tagged in twips
RTF does hold the original page size for the document
Kats2512 8-Sep-17 2:37am    
for a question that has been asked and answered 6 years ago!
So I tried this today and here is a work around. The rich text box does not have a setting but RTF does have tags for this in version 1.5.

An RTF file is a tagged format created MANY years ago to work with 7 bit ASCII and * bit mac computers.

The TAGS are all written in ASCII so you can open the file and insert the settings that you want to have in the file with your favorite method of parsing files.
WINDOWS uses Twips 1440 to an inch so A4 is rounding down
Width 8.27 * 1440=11,908
Height is 11.69 * 1440= 16,833
I set the margins at default margins
We can insert this on any line the tag is \line so we look for a \line and insert new tags. most anywhere will work in most cases.

To make this easy I will do this the old fashion way, using FILEOPEN

Dim PageSize As String
'Comment out one
PageSize = "
\paperw12240\paperh15840\margl1440\margr1440\margt1800\margb1800 "

PageSize = " \paperw16834\paperh11909\margl1440\margr1900\margt1800\margb1800\landscape "
Now open the file stick it in a collection
Dim LineCol As New StringCollection
Dim InData As String
FileOpen(1, "C:\FILENAME.rtf", OpenMode.Input)
Do Until EOF(1) <> False
InData = LineInput(1)
'NOw write the data back out
FileOpen(1, "C:\FILENAME.rtf", OpenMode.Output)
Dim found As Boolean = vbFalse
Dim Find As Integer
For Each InData In LineCol
If Not found Then
Find = InStr(InData, "\line", CompareMethod.Text)
If Find > 0 Then
'work is getting done here we found a \line adding tags
InData = InData.Insert(Find + 5, PageSize)
found = vbTrue
End If
End If
Print(1, InData)
I have tested this at the office and had some issues with landscape but this works for me
the other tag that also works for landscape is \lndscpsxn
If you were using letter size do the math and you can dedicate the paper using \ltrsect for letter and
for landscape letter.
It is a work around but it does work.
You could make your own class, inherit the richtextbox and add this to it.
Share this answer
Graeme_Grant 7-Sep-17 18:45pm    
WHY are you answering a 6-YEAR-OLD question that has ALREADY ACCEPTED an answer. Please don't as this is considered REP FARMING and if not stopped can get you banned.

Focus on current question ONLY - there are always plenty waiting for help.
Craig P Williams Sr 8-Sep-17 17:04pm    
Sorry.....I'll post an article about the issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900