0

I'm printing two documents with Single button click. When i do this,

I have an error like : Dialog boxes must be open by user.

Here is the code :

PrintDocument monDocument = new PrintDocument();
btPrint.IsEnabled = true;

monDocument.PrintPage += new EventHandler<PrintPageEventArgs>(monDocument_PrintPage);          
monDocument.Print("Fiche");
System.Threading.Thread.Sleep(5000);

if (itm.Letter != null || itm.Letter != "")
{
    _lineIndex = 0;
    _documentBodyLines = new List<string>();
    string[] lines = tbLetter.Text.Split(new char[] { '\r' }, StringSplitOptions.None);
    _documentBodyLines.AddRange(lines);

    PrintDocument maLetter = new PrintDocument();
    maLettreMotiv.PrintPage += new EventHandler<PrintPageEventArgs>(maLettreMotiv_PrintPage);
    maLettreMotiv.Print("Letter");
}

Here, itmis the object I'm currently on.

The line throwing the error is the last one. I tried adding a sleep, but no results.

When I do this separately (one print with comment), this is working, but I don't find a way to do the two documents printing.

provençal le breton
  • 1,428
  • 4
  • 26
  • 43

1 Answers1

0

Firstly, there is a bug where if you put a break point in a print routine, you might end up with that error message.

Secondly, you should look at HasMorePages property. By setting it to true, you can print multi-page reports.

Chui Tey
  • 5,436
  • 2
  • 35
  • 44