다음을 통해 공유


차트 인쇄

Windows Forms용 차트 컨트롤에서 차트 그림을 인쇄할 수 있습니다.이렇게 하려면 차트 컨트롤의 Printing 속성을 사용합니다.이 개체는 현재 데이터 뷰에서 스크롤 막대를 제외한 모든 차트 컨트롤 요소를 인쇄합니다.

인쇄 대화 상자를 호출하거나 백그라운드에서 인쇄할 수 있습니다.Printing 개체에서 PrintDocument 속성을 사용하여 페이지 여백 등과 같은 인쇄 속성을 설정할 수 있습니다.

사용자 지정 인쇄

다른 문서 요소를 포함하는 문서에서 차트 그림을 인쇄하려면 PrintPageEventHandler 내의 PrintPaint 메서드를 호출합니다.문서에서 차트 그림의 위치를 정의하는 Rectangle 개체와 함께 PrintPaint 메서드를 PrintPageEventArgs 개체의 Graphics 속성에 전달해야 합니다.

다음 코드에서는 한 줄의 텍스트가 있고 그 뒤에 차트 그림과 또 한 줄의 텍스트가 있는 문서를 인쇄하는 방법을 보여 줍니다.

' 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); 
}

참고 항목

기타 리소스

차트 컨트롤 사용