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一度使用してすべてのファイルをプリンターに送信する方法はありますか。ユーザーはフォルダを選択し、フォルダ内のすべてのドキュメントに対して 1 つの印刷設定を設定してから、印刷を実行できますか?

4

1 に答える 1

1

このサンプル コードを試してください。

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
    ...
}
于 2014-02-26T12:34:20.710 に答える