Share via


方法 : Windows フォームでグラフィックスを印刷する

更新 : 2007 年 11 月

Windows ベースのアプリケーションでグラフィックスの印刷が必要になることはよくあります。Graphics クラスは、画面やプリンタなどのデバイスにオブジェクトを描画する手段を提供します。

グラフィックスを印刷するには

  1. フォームに PrintDocument コンポーネントを追加します。

  2. PrintPage イベント ハンドラで、PrintPageEventArgs クラスの Graphics プロパティを使用して、印刷するグラフィックスの種類をプリンタに指示します。

    外接する四角形内に青い楕円を作成するために使用されるイベント ハンドラのコード例を次に示します。四角形の位置は点 100, 150 で始まり、寸法は幅 250、高さ 250 です。

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
       e.Graphics.FillEllipse(Brushes.Blue, New Rectangle(100, 150, 250, 250))
    End Sub
    
    private void printDocument1_PrintPage(object sender, 
    System.Drawing.Printing.PrintPageEventArgs e)
    {
       e.Graphics.FillRectangle(Brushes.Blue, 
         new Rectangle(100, 150, 250, 250));
    }
    
    private void printDocument1_PrintPage(Object sender,
    System.Drawing.Printing.PrintPageEventArgs e)
    {
       e.get_Graphics().FillRectangle(Brushes.get_Blue(),
          new Rectangle(100, 150, 250, 250));
    }
    
    private:
       void printDocument1_PrintPage(System::Object ^ sender,
          System::Drawing::Printing::PrintPageEventArgs ^ e)
       {
          e->Graphics->FillRectangle(Brushes::Blue,
             Rectangle(100, 150, 250, 250));
       }
    

    (Visual C#、Visual J#、および Visual C++) フォームのコンストラクタに次のコードを挿入してイベント ハンドラを登録します。

    this.printDocument1.PrintPage += new
       System.Drawing.Printing.PrintPageEventHandler
       (this.printDocument1_PrintPage);
    
    this.printDocument1.add_PrintPage(new System.Drawing.Printing.PrintPageEventHandler(
    this.printDocument1_PrintPage));
    
    this->printDocument1->PrintPage += gcnew
       System::Drawing::Printing::PrintPageEventHandler
       (this, &Form1::printDocument1_PrintPage);
    

参照

参照

Graphics

Brush

その他の技術情報

Windows フォームにおける印刷のサポート