Question Adjust a richtext box to a page setup dialog option

mrtutorial08

Member
Joined
Sep 4, 2008
Messages
20
Programming Experience
1-3
How could a person adjust a richtext box to the option selected in the page setup dialog? This is pretty though or pretty easy. Well I couldn't figure it out so I need your help.

Thanks in advance!
 
Like in Microsoft Word....When a users selects a page size( A4 for example) the Richtextbox or the document box in ms word changes its size to the A4 size...If a user slects A5 then the richtextbox size changes to the size of the A5 page...Get it?

How can I make an extended richtextbox change its size to the page size selected in the page setup dialog...
 
The sizes for A4 A5 etc are all pretty much constant, and you can adjust the size of a RichTextbox to pretty much any thing you like by setting it's Width and Height Properties.
 
...i just used them as examples...there are MUCH MORE OPTIONS IN THE PAGE SETUP DIALOG..................Like... MS Word Changes its page size to the page type select in the page setup... I have a page setup dialog and I want it to change the richtext box size according to the page setup option selected...

If not that...what A4 A5 richtextbox size do you suggest? Give the proper height and width units please...for example (200,300) .....
 
Well you can get all width and height measurements you need from MS Word they are all in there. As for how you adjust the rich text box well in MS Word it is simply a combobox with values in it A4, A3 etc and each of these values relates to a specifed dimension. Im not going to pretend to know how MS Word works and if infact that is a richtextbox that you see in Word but the principle is the same.

Off the top of my head you could have a 2 dimensional array that holds the width and height values, or you could use a hashtable any number of possibilites. Selecting A4 from your combobox can be in an enum somewhere that has the value 1, and in this case in your hashtable or array item 1 can be the size you need to adjust yuor RTB to. In the case of A4 - 21 cm x 29.7 cm
 
...What units does VB.NET use? So I can convert those into the Units that are used by VB.NET...

Give an example please...

So I should use a combo box in which has option of A4 A5 8 X 10 or whatever... and when a user selects that option it the rtb size changes to that?
That sounds like a good idea...

Hopefully that will work..

BTW This is what I am actually trying to get... Like in MS Word you do all your formatting and stuff drag images here and there...When you click print preview it comes exactly the way you formatted it... How could I do that with a rich text box? When I format my text here and there and do the stuff it comes out differently....


Thanks for your help though....ANY MORE HELP FROM ANY ONE IS HIGHLY APPRECIATED! =D
 
Last edited:
VB.NET:
If Me.PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim ps As Printing.PaperSize = Me.PageSetupDialog1.PageSettings.PaperSize 
    Using g As Graphics = Me.CreateGraphics
        If Me.PageSetupDialog1.PageSettings.Landscape Then
            Me.RichTextBox1.Height = CInt(ps.Width / 100 * g.DpiX)
            Me.RichTextBox1.Width = CInt(ps.Height / 100 * g.DpiY)
        Else
            Me.RichTextBox1.Width = CInt(ps.Width / 100 * g.DpiX)
            Me.RichTextBox1.Height = CInt(ps.Height / 100 * g.DpiY)
        End If                
    End Using
End If
You can also put PageSettings.Margins into play.

...What units does VB.NET use? So I can convert those into the Units that are used by VB.NET...
Forms units are in pixels. The PaperSize resolution in hundreds of an inch, and as you see do not change with different page setup orientation. The link between these is the graphics resolution of the display that tells DPI (dots/pixels per inch).
 
Thanks for the code....But Can I ask you a small favor...

Where am I supposed to put that Code? On a Page setup button or what?

Btw if this is helpful to you to help me(that sounds funny lol) I am using an extended rich text box control since that provides me The printing capabilities I need for my word processor..

As Always....
Thanks for your help though....ANY MORE HELP FROM ANY ONE IS HIGHLY APPRECIATED! =D
 
Please...I am confused with the code... JohnH your code doesn't work for me??

I want the RICH TEXT BOX to have the same size as a normal page would...

My Problem(EXAMPLE):
I do all the formatting of the text in the way I want to in MrWord...
But when I click Print Preview the print preview dialog shows up and the Heading Text (in my rich text box that text is at the far right of the page)
is on the next Line)

Example:
I have this problem. I have this problem. I have this problem. <--Thats how it appers when the user types it in to the richtext box

But when the user clicks print preview this is what comes out:
I have this problem. I have this problem.
I have this problem.



I think a pic would explain better

 
Last edited:
Are you sure you're using the same font and page settings for the preview as for RTB? When comparing the texts of your screenshot close to each other there is a slight mismatch in spacing as seen in here, I have cut half the text of preview to compare with RTB:
align1.jpg

When I do the same the font alignment match exactly:
align2.jpg
 
Back
Top