How do I find the printable client width and height?

I have the following code:

    private void button1_Click(object sender, System.EventArgs e)
    {
      PrintDialog pd = new PrintDialog();
      PrintDocument imageDoc = new  PrintDocument();
      pd.Document = imageDoc ;
      imageDoc.PrintPage += new PrintPageEventHandler(imageDoc_PrintPage);
      pd.ShowDialog();
    }

    private void imageDoc_PrintPage(object sender, PrintPageEventArgs e)
    {
      using( Bitmap drawImage = new Bitmap("myImage.jpg") )
      {
        // Draw the image to the printer
        e.Graphics.DrawImage( drawImage, new Point(10,10) ) ;
      }


Within imageDoc_PrintPage, how would you determine the width and height of the client space (printable space within the page) so that you can create a rectangle suitable for a particular image

Thanks!



Answer this question

How do I find the printable client width and height?

  • RotoLuter

    You are right there. Use the PrintPageEventArgs object "e" to get the MarginBounds property

    Rectangle pageRect = new Rectangle(e.MarginBounds.Left,  e.MarginBounds.Top ,     e.MarginBounds.Width,  e.MarginBounds.Height);
        
    You can also look at the header and footer height values and then calculate the bounds
    left for the page.

  • Ayman Shoukry - MSFT

     

    Thank you.  :)


  • How do I find the printable client width and height?