|
-
Sep 21st, 2007, 01:44 AM
#1
Thread Starter
Member
Printing in center of A4 document
Hi boys,
I want in my app to print on A4 page a title in center of it.
There's a method to do this or i must calculate the size of page, the site of title and than specify the corect position?
Thanks in advance.
Moodie.
-
Sep 21st, 2007, 02:19 AM
#2
Re: Printing in center of A4 document
You have to do some of the work and some is done for you. You have to determine the width of the page, then you specify an area of that width when you call DrawString. You also pass a StringFormat with its LineAlignment set to Center and then your string will be drawn in the centre of the area, thus the centre of the page.
-
Sep 21st, 2007, 02:25 AM
#3
Thread Starter
Member
Re: Printing in center of A4 document
Ok... I try to read some tutorial of this argument.
One question if you know "at fly"...
1) I set the GraphicsUnit of Font and PageUnit to "Document".
2) I create a title string and measure it with "MeasureString" method.
Now, if i do this operation the text will be in center, right?
Operation:
StartPosX = WidthSizeOfDocument - WidthOfString / 2
The question is (also releated with your answers), how can i get at run time the size od my Page?
-
Sep 21st, 2007, 02:33 AM
#4
Re: Printing in center of A4 document
The width of the string is irrelevant. Like I said, all you need is the width of the page. You then call DrawString and specify an area the full width of the page and specify the alignment as centred. Your string will be centred in the area and thus centred on the page, regardless of how long the string itself is.
-
Sep 21st, 2007, 02:54 AM
#5
Thread Starter
Member
Re: Printing in center of A4 document
Ok, but how i can calculate the width of tha page at run time?
There isn't a method Document.Width or similar...
Am i so so newbi?
-
Sep 21st, 2007, 07:42 AM
#6
Re: Printing in center of A4 document
I don't have local MSDN on this machine and I won't be searching through the online version, but it is just about as simple as that. Start at the PrintDocument and check what properties it has, then check their properties. I'm guessing that it's somewhere in the PageSettings class, which I think is access from PrintDocument.PrinterSettings.PageSettings, but you should check to confirm that. It just takes a bit of time and effort looking through the available members on MSDN.
-
Sep 21st, 2007, 07:58 AM
#7
Re: Printing in center of A4 document
The PrintPage event handler (in which all printing commands are done) has a parameter:
Code:
ByVal e As System.Drawing.Printing.PrintPageEventArgs
This has a member PageBounds that is a rectangle which is the size of the page.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|