PrintDocument で印刷可能領域を取得する方法

  PrintDocument で印刷可能領域を取得するには、PrintDocument のオーバーライドした OnPrintPage メソッド内で、PrintEventArgs のプロパティ「e.MarginBounds」で取得します。
【使い方】

 ページ印刷時に印刷可能な領域を取得する例。
/// <summary>
/// ページの印刷時に呼び出されるイベントメソッド
/// </summary>
/// <param name="e">ページ印刷用イベントデータ。</param>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
{
    //Debug.WriteLine("OnPrintPage Start");

    Graphics g = e.Graphics;
    g.PageUnit = GraphicsUnit.Millimeter;        //Printイメージの単位を㎜に設定する

    //表描画領域を設定 (㎜単位に変換する)
    float x      = (float)e.MarginBounds.Left * 0.254F;
    float y      = (float)e.MarginBounds.Top * 0.254F;
    float width  = (float)e.MarginBounds.Width * 0.254F;
    float height = (float)e.MarginBounds.Height * 0.254F;

    //===============================================
    // ここにページ印刷内容&追加印刷有無を定義する
    //===============================================

    //Debug.WriteLine("OnPrintPage End");
}
【注意】
 e.MarginBounds で取得する領域(Rectangle)の単位は、1/100 インチです。 e.Graphics.PageUnit の単位に応じて変換が必要です。
戻る