1
현재 프린터 설정을 선택하고 인쇄 할 수있는 PrintDialog
을 엽니 다. 순간동일한 프린터 설정으로 여러 파일 인쇄
내가 코드 아래 사용하고
var files = Directory.GetFiles(sourceFolder);
foreach (var file in files)
{
var pdoc = new PrintDocument();
var pdi = new PrintDialog
{
Document = pdoc
};
if (pdi.ShowDialog() == DialogResult.OK)
{
pdoc.DocumentName = file;
pdoc.Print();
}
}
한 번 PrintDialog
를 사용하여 프린터에 모든 파일을 보낼 수있는 방법이 있나요. 따라서 사용자는 폴더를 선택하고 폴더 안의 모든 문서에 대해 하나의 인쇄 설정을 지정한 다음 인쇄를 할 수 있습니까? 바로 파일을 인쇄 시도,
var files = Directory.GetFiles(sourceFolder);
if (files.Length != 0)
{
using (var pdoc = new PrintDocument())
using (var pdi = new PrintDialog { Document = pdoc, UseEXDialog = true })
{
if (pdi.ShowDialog() == DialogResult.OK)
{
pdoc.PrinterSettings = pdi.PrinterSettings;
// ************************************
// Pay attention to the following line:
pdoc.PrintPage += pd_PrintPage;
// ************************************
foreach (var file in files)
{
pdoc.DocumentName = file;
pdoc.Print();
}
}
}
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
string file = ((PrintDocument)sender).DocumentName; // Current file name
// Do printing of the Document
...
}
야 : –
'PrintDialog'가 표시 되었습니까? 그렇지 않은 경우 대화 상자의 속성 인 UseEXDialog = true를 설정하십시오. 이를 반영하기 위해 샘플을 업데이트했습니다. – Dmitry
또한 'pdoc.PrintPage' 이벤트 핸들러에서 인쇄를 구현해야합니다. 샘플이 업데이트되었습니다. – Dmitry