Finding out max available print area

Posted by Armagan on Stack Overflow See other posts from Stack Overflow or by Armagan
Published on 2010-05-29T19:26:08Z Indexed on 2010/05/29 19:32 UTC
Read the original article Hit count: 282

Filed under:
|
|

I'm trying to find out max available area on my printer. I've printed a simple rectangle trying out different boundary variables. My question is, why doesn't first two work correctly? They don't print a full rectangle on the paper, only the left and top sides are drawn. Why does only the third one prints a full rectangle? I was under the impression of that all three should be working correctly. What am I missing?

Here's my code:

this.printDocument1.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

...
private void PrintPage(object sender, PrintPageEventArgs e)
{
    //Method 1, no right and bottom sides are printed
    e.Graphics.DrawRectangle(new Pen(Color.Black, 1), e.PageBounds);

    //Method 2, same as Method 1
    e.Graphics.DrawRectangle(new Pen(Color.Black, 1), e.MarginBounds);

    //Method 3, works correctly
    e.Graphics.DrawRectangle(new Pen(Color.Black, 1), new Rectangle((int)e.Graphics.VisibleClipBounds.X, (int)e.Graphics.VisibleClipBounds.Y, (int)e.Graphics.VisibleClipBounds.Width, (int)e.Graphics.VisibleClipBounds.Height));
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET