M
Martin R Pettersson
Guest
Regardless of the printer selected from the printdialog1.showDialog() the print job always goes to the default printer, not the selected one. What am I missing or doing wrong?
here is my part of the print code:
Function PrintTest(code As Integer, ans As String)
'code 1: print score only
'code 2: print full test
'code 3: print answer sheet
PrintTest = True
Dim LastItem As Integer, FirstItem As Integer, tmp(30) As String
'Dim xCol4 As Long, xCol5 As Long
Dim yLine As Long
Dim PageNum As Integer, LineCount As Integer, NumOfPages As Integer
Dim style As MsgBoxStyle = MsgBoxStyle.Information Or MsgBoxStyle.OkOnly
'define printer object
Dim Prnt As New Printer
Dim DoSlctd As Boolean, PrintHeader As Boolean
Dim PrintDocument1 As New PrintDocument
Dim Mydate As String
Mydate = Date.Today
'Select a Printer
If PrinterSelected = False Then
Dim PrintDialog1 As New PrintDialog()
Dim result As DialogResult = PrintDialog1.ShowDialog()
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
If (result <> DialogResult.OK) Then
Exit Function
End If
PrinterSelected = True
End If
'Printer selected. Start printing
LineCount = 1
PageNum = 1
NumOfPages = 1
DoSlctd = False
PrintHeader = True
FirstItem = 1
LastItem = MainForm.TotalQuestions.Text
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If code = 1 Then 'Print the test results
'Print Page Title
Try
Prnt.Print()
Prnt.Print()
Prnt.FontSize = 14
Prnt.FontBold = True
Prnt.CurrentX = Twips("2 3/4")
Prnt.Print("FISD Transportation Driver Testing")
Prnt.Print("_________________________________________________________________________________________________")
'Print the Line titles
Prnt.Print() 'space one line
Prnt.Print()
Prnt.FontSize = 12
Prnt.FontBold = True
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("D A T E :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(Mydate)
Prnt.Print()
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("D R I V E R :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(ans)
Prnt.Print()
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("T E S T :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(Trim(MainForm.ListBox1.Text))
Prnt.Print()
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("S C O R E :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(MainForm.Label3.Text & " %")
Prnt.Print()
Prnt.Print()
Prnt.Print("_________________________________________________________________________________________________")
Prnt.EndDoc() 'Print it.
Catch ex As Exception
MsgBox("Error printing Test Results." & vbCrLf & ex.Message)
Prnt.EndDoc()
Prnt.KillDoc()
End Try
Exit Function
End If
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If code = 2 Then 'Print Full Test
'Print two questions per page
Continue reading...
here is my part of the print code:
Function PrintTest(code As Integer, ans As String)
'code 1: print score only
'code 2: print full test
'code 3: print answer sheet
PrintTest = True
Dim LastItem As Integer, FirstItem As Integer, tmp(30) As String
'Dim xCol4 As Long, xCol5 As Long
Dim yLine As Long
Dim PageNum As Integer, LineCount As Integer, NumOfPages As Integer
Dim style As MsgBoxStyle = MsgBoxStyle.Information Or MsgBoxStyle.OkOnly
'define printer object
Dim Prnt As New Printer
Dim DoSlctd As Boolean, PrintHeader As Boolean
Dim PrintDocument1 As New PrintDocument
Dim Mydate As String
Mydate = Date.Today
'Select a Printer
If PrinterSelected = False Then
Dim PrintDialog1 As New PrintDialog()
Dim result As DialogResult = PrintDialog1.ShowDialog()
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
If (result <> DialogResult.OK) Then
Exit Function
End If
PrinterSelected = True
End If
'Printer selected. Start printing
LineCount = 1
PageNum = 1
NumOfPages = 1
DoSlctd = False
PrintHeader = True
FirstItem = 1
LastItem = MainForm.TotalQuestions.Text
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If code = 1 Then 'Print the test results
'Print Page Title
Try
Prnt.Print()
Prnt.Print()
Prnt.FontSize = 14
Prnt.FontBold = True
Prnt.CurrentX = Twips("2 3/4")
Prnt.Print("FISD Transportation Driver Testing")
Prnt.Print("_________________________________________________________________________________________________")
'Print the Line titles
Prnt.Print() 'space one line
Prnt.Print()
Prnt.FontSize = 12
Prnt.FontBold = True
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("D A T E :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(Mydate)
Prnt.Print()
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("D R I V E R :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(ans)
Prnt.Print()
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("T E S T :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(Trim(MainForm.ListBox1.Text))
Prnt.Print()
yLine = Prnt.CurrentY 'Current position of "y" (line)
Prnt.CurrentX = Twips("1")
Prnt.Print("S C O R E :")
Prnt.FontBold = False
Prnt.CurrentX = Twips("2 1/8")
Prnt.CurrentY = yLine - 1
Prnt.Print(MainForm.Label3.Text & " %")
Prnt.Print()
Prnt.Print()
Prnt.Print("_________________________________________________________________________________________________")
Prnt.EndDoc() 'Print it.
Catch ex As Exception
MsgBox("Error printing Test Results." & vbCrLf & ex.Message)
Prnt.EndDoc()
Prnt.KillDoc()
End Try
Exit Function
End If
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If code = 2 Then 'Print Full Test
'Print two questions per page
Continue reading...