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.
Printable View
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.
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.
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?
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.
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?
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.
The PrintPage event handler (in which all printing commands are done) has a parameter:
This has a member PageBounds that is a rectangle which is the size of the page.Code:ByVal e As System.Drawing.Printing.PrintPageEventArgs