Displaying Printing Status!

Displaying Printing Status!

Post by Ajab Gaja » Fri, 08 Apr 2005 16:02:49


Hi all,

I am developing a printing application where I want to show printing
status to the user. Like, when user clicks on print button, a form will be
displayed which will have a cancel button on it. The form will display
status Like "Printing page 1 of 10". In my case, the form is being displayed
properly but it is not receiving the cancel_click event as it is updating
itself in OnPrintPage event. Here is my code:

These methods are defined in a class derived from PrintDocument.

Protected Overrides Sub OnPrintPage(ByVal e As
System.Drawing.Printing.PrintPageEventArgs)

Dim g As Graphics

Try
g = e.Graphics

g.DrawString("Print",f1,Brushes.Black, 100 + page_no, 100 + page_no)
' f1 is a Font object declared at module level.

' page_no is current page being printed and pages is total number of
pages to be printed, f.setLabel function sets the text of the label on the
form

f.setLabel("Printing " + page_no.ToString + " of " + pages.ToString)
f.Update()
page_no += 1

' When a user clicks on cancel, the event 'cancelPrinting' gets fired and
it sets cancel_printing = true, where cancel_printing is a module level
variable.The problem is that the form is not receiving any event like,
click, mouseMove etc.

If cancel_printing = True Then
e.Cancel = True
e.HasMorePages = False
cancel_printing = False
End If
If pages >= page_no Then
e.HasMorePages = True
Else
e.HasMorePages = False
page_no = 1
End If

Catch ex As Exception
MessageBox.Show(ex.Message)

End Try

End Sub

Public Sub printPages()

Try
MyBase.PrintController = New StandardPrintController
f = New frmPrintProgress ' This is the form with cancel button
on it and it displays the status.
f.Show()
MyBase.Print()
f.Dispose()

Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try

End Sub

One more question,
Whenever one calls form.show, does Windows create a new thread for
the form or it runs in the same thread?

Thanks in Advance.

--
.Net Developer