I have a program which prints a series of pages, stopping after each page to ask the user to verify they want it printed and insert the paper to printed to. The problem is, in some situations, it goes and prints the item, which pops up a print progress window, and then when that window goes away it tries to return focus to the form. But by that time, the next modal dialog is being shown, and that prevents the original window from being refocused.
Sometimes it even brings a window from the background to cover my original form. It works fine if I don't show any dialogs after printing, but that's not really an option. This only occurs with certain printers.
If anyone else has run into this, how did you fix it?
Sample code:
private void Print(int ItemCount)
{
for (int i = 0; i < ItemCount; i++)
{
MessageBox.Show("Insert paper to print to.");
using (PrintDocument PrintDoc = new PrintDocument())
{
PrintDoc.PrintPage += new PrintPageEventHandler(PrintDoc_PrintPage);
PrintDoc.Print();
}
}
}
void PrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Black, new Rectangle(10, 10, 100, 100));
e.HasMorePages = false;
}