次の方法で共有


グラフの印刷

Windows フォームのグラフ コントロールでは、グラフのピクチャを印刷できます。 この場合、グラフ コントロールの Printing プロパティを使用します。 このオブジェクトを使用すると、スクロール バーを除き、現在のデータ ビューにあるすべてのグラフ コントロールの要素が印刷されます。

[印刷] ダイアログ ボックスを呼び出すことや、バックグラウンドで印刷することができます。 Printing オブジェクトでは、PrintDocument プロパティを使用して、ページの余白など印刷のプロパティを設定できます。

カスタム印刷

他のドキュメント要素があるドキュメントに含まれるグラフのピクチャを印刷するには、PrintPageEventHandler 内で PrintPaint メソッドを呼び出します。 PrintPaint メソッドには、PrintPageEventArgs オブジェクトの Graphics プロパティと、ドキュメントに含まれるグラフのピクチャの位置を定義する Rectangle オブジェクトを渡す必要があります。

次のコードは、1 行のテキスト、グラフのピクチャ、その後にもう 1 行のテキストを含むドキュメントを印刷する方法の例です。

' Create new PrintDocument 
Dim pd As New System.Drawing.Printing.PrintDocument() 
' Add the event handler, and then print 
AddHandler pd.PrintPage, AddressOf pd_PrintPage 
' Print the document 
pd.Print() 
... 
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) 
   ' Create and initialize print font 
   Dim printFont As New System.Drawing.Font("Arial", 10) 
   ' Create Rectangle structure, used to set the position of the chart 
   Dim myRec As New System.Drawing.Rectangle(10, 30, 150, 150) 
   ' Draw a line of text, followed by the chart, and then another line of text 
   ev.Graphics.DrawString("Line before chart", printFont, Brushes.Black, 10, 10) 
   chart1.Printing.PrintPaint (ev.Graphics, myRec) 
   ev.Graphics.DrawString("Line after chart", printFont, Brushes.Black, 10, 200) 
End Sub
// Create new PrintDocument 
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); 
// Add a PrintPageEventHandler for the document 
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); 
// Print the document 
pd.Print(); 
...
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
   // Create and initialize print font 
   System.Drawing.Font printFont = new System.Drawing.Font("Arial", 10); 
   // Create Rectangle structure, used to set the position of the chart Rectangle 
   myRec = new System.Drawing.Rectangle(10, 30, 150, 150); 
   // Draw a line of text, followed by the chart, and then another line of text 
   ev.Graphics.DrawString("Line before chart", printFont, Brushes.Black, 10, 10); 
   chart1.Printing.PrintPaint (ev.Graphics, myRec); 
   ev.Graphics.DrawString("Line after chart", printFont, Brushes.Black, 10, 200); 
}

参照

その他の技術情報

グラフ コントロールの使用