Results 1 to 7 of 7

Thread: Printing in center of A4 document

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    50

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    50

    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?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    50

    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?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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
  •  



Click Here to Expand Forum to Full Width