방법: PrintDialog 만들기 및 표시
업데이트: 2007년 11월
이 예제에서는 PrintDialog 상자를 표시하는 방법을 보여 줍니다.
예제
다음 예제에서는 다음과 같은 방법을 통해 인쇄 대화 상자를 표시하는 방법을 보여 줍니다.
PrintDialog 인스턴스화
PageRangeSelection 및 UserPageRangeEnabled 속성을 설정하여 페이지 범위 선택 옵션 구성
ShowDialog 메서드를 호출하여 인쇄 대화 상자 표시
<Button Width="200" Click="InvokePrint">Invoke PrintDialog</Button>
...
private void InvokePrint(object sender, RoutedEventArgs e)
{
// Create the print dialog object and set options
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
// Display the dialog. This returns true if the user presses the Print button.
Nullable<Boolean> print = pDialog.ShowDialog();
if (print == true)
{
XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
}
}
전체 샘플을 보려면 PrintDialog 샘플을 참조하십시오.