ThisIsABird ThisIsABird - 2 years ago 94 Question - PrintDialog not appearing

I'm almost done with my system. All I need to finish is the print process. Sadly, the print dialog is not appearing.

Here's the code for the printing process

Private Sub PrintReceipt()
Dim printdialog As New PrintDialog
Dim printdocument As New Printing.PrintDocument

printdialog.Document = printdocument

AddHandler printdocument.PrintPage, AddressOf printdocument_printPage

Dim result As DialogResult

If (result = DialogResult.OK) Then
End If
End Sub

There is nothing wrong with the printdocument_printpage, which is basically just what it will be printing, yet, since printing hasn't even begun, I won't bother putting it here unless requested.

I want the said dialog to appear after the transaction has been saved. which its not doing for some reason. And here's the code for the save transaction.

Dim payment As New Payment
mydbcon = New MySqlConnection
mydbcon.ConnectionString = "server=localhost;userid=root;password=;database=sdudb"
Dim reader As MySqlDataReader

If e.PaymentSuccess = True Then
Dim Query As String
Query = "select * from itemstored"
COMMAND = New MySqlCommand(Query, mydbcon)
reader = COMMAND.ExecuteReader()
While reader.Read
insertTranscation(reader.GetString("itemname"), reader.GetString("price"))
End While
Catch ex As Exception
End Try
End If

Ignore the mysql here. It's not the main problem.

Answer Source

The dialog will not show if you don't tell it to. You've forgotten to call printdialog.ShowDialog() in your code, and you also never set result to anything before checking it.

It's a simple fix:

Dim result As DialogResult = printdialog.ShowDialog()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download