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, itm
is 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.