|
-
Aug 13th, 2003, 03:37 PM
#1
Thread Starter
New Member
Help! VB.Net code only works on some printers. Not a XEROX Document Centre 440ST.
Please Help!!! I am trying to print from a List Box in VB.Net. It works on most printers eg. HP Laser Printer however, I need to be able to print it on a XEROX Document Center 440ST. It prints however the text comes out all garbled in symbols. Has anyone had a similar problem and do you know how to resolve it? My code is below. Thank you!
Private Sub Print_Load()
'***************************************************************************************************
'Print_Load()- loads the data selected from the listbox "lstdata" into an array called strPrintData
'***************************************************************************************************
Dim x As Integer = lstData.SelectedIndices.Count - 1
ReDim strPrintData(x)
lstData.SelectedItems.CopyTo(strPrintData, 0)
'A new selection has been made to print reset the page counter to 0
PageNumber = 0
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
'***************************************************************************************************
'cmdPrint_Click()- This is the print button. It checks to see if the user has made a selection from
'the listbox "lstdata". If not there is nothing to print and an error msg is displayed. If there
'has been a selection, The Print_Load() procedure is called to load the data to be printed. A
'print dialog box is then created.
'***************************************************************************************************
If lstData.SelectedItem = "" Then
MsgBox("No text was selected in the EJV window to print.", MsgBoxStyle.Critical, "EJV Error")
Else
PreviewFlag = False
Print_Load()
Try
Dim dlgSettings As New PrintDialog()
dlgSettings.Document = MyDoc
'Show the print dialog box
Dim Result As DialogResult
Result = dlgSettings.ShowDialog()
'Print the documnet
If Result = DialogResult.OK Then MyDoc.Print()
Catch ex As Exception
MessageBox.Show(ex.Message & "Please Contact Your Network Administrator")
End Try
End If
End Sub
Private Sub MyDoc_PrintPage(ByVal sender As Object, _
ByVal e As PrintPageEventArgs) Handles MyDoc.PrintPage
'***************************************************************************************************
'MyDoc_PrintPage()- This is the event handler for the printing. It defines the font,
'margins, keeps a running total of the page numbers.
'***************************************************************************************************
Try
' Define the font and determine the line height.
Dim MyFont As New Font("Arial", 10)
Dim LineHeight As Single = MyFont.GetHeight(e.Graphics)
' Create variables to hold position on page.
Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
' Increment page counter and the refresh display.
stbInfo.Text = ""
If PreviewFlag = False Then
PageNumber += 1
stbInfo.Text &= vbNewLine & "Sending Page " & PageNumber & " ..."
End If
' Print all the information that can fit on the page.
Do
e.Graphics.DrawString(strPrintData(Offset), MyFont, Brushes.Black, x, y)
Offset += 1
y += LineHeight
Loop Until (y + LineHeight) > e.MarginBounds.Bottom Or Offset > strPrintData.GetUpperBound(0)
' Determine if another page is needed.
If Offset < strPrintData.GetUpperBound(0) Then
e.HasMorePages = True
Else
Offset = 0
stbInfo.Text &= vbNewLine & "Print or Preview Completed"
End If
Catch ex As Exception
MessageBox.Show(ex.Message & "Please Contact Your Network Administrator")
End Try
End Sub
Private Sub cmdPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPreview.Click
'***************************************************************************************************
'cmdPreview_Click()- This is the print preview button. Like the print button, it checks to see if
'the user has made a selection from the listbox "lstdata". If not there is nothing to print and an
'error msg is displayed. If there has been a selection, The Print_Load() procedure is called to
'load the data to be printed. A print preview dialog box is then created and sent to the top of the
'displayed forms
'***************************************************************************************************
stbInfo.Text = ""
Dim dlgPreview As New PrintPreviewDialog()
If lstData.SelectedItem = "" Then
MsgBox("No text was selected in the EJV window to print.", MsgBoxStyle.Critical, "Selection Error")
Else
Print_Load()
dlgPreview.Document = MyDoc
dlgPreview.Show()
dlgPreview.TopMost() = True
PreviewFlag = True
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|