次の方法で共有


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

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(System::Object ^ sender,
          System::Drawing::Printing::PrintPageEventArgs ^ e)
       {
          e->Graphics->FillRectangle(Brushes::Blue,
             Rectangle(100, 150, 250, 250));
       }
    

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

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

参照

参照

Graphics

Brush

その他の技術情報

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