You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ITSM/.svn/pristine/11/11cbc133018c4f06da5993f26f2...

73 lines
2.4 KiB

Imports System
Imports System.Windows.Forms
Imports System.Drawing.Printing
Public Class Form1
'declarations somewhere
Public Shared pd As New System.Drawing.Printing.PrintDocument
Public Shared PrintFont As Font
Public Shared FiletoPrint As System.IO.StreamReader
Dim prtdoc As New PrintDocument
Dim strDefaultPrinter As String = prtdoc.PrinterSettings.PrinterName
'in the function to print
'Printpage function
Public Shared Sub printPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = 0
Dim topmargin As Single = 0
Dim line As String = Nothing
Try
e.PageSettings.Landscape = False
linesPerPage = e.MarginBounds.Height / PrintFont.GetHeight(e.Graphics)
While count < linesPerPage
line = FiletoPrint.ReadLine
If line Is Nothing Then Exit While
yPos = topmargin + count * PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, PrintFont, Brushes.Black, leftMargin, yPos, New StringFormat)
count += 1
End While
If Not (line Is Nothing) Then e.HasMorePages = True
Catch ex As Exception
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.ShowDialog()
PrintFont = New Font("Arial", 10)
FiletoPrint = New System.IO.StreamReader(Me.OpenFileDialog1.FileName)
AddHandler pd.PrintPage, New System.Drawing.Printing.PrintPageEventHandler(AddressOf printPage)
'pd.PrinterSettings.PrinterName = Me.ComboBox1.SelectedText
pd.Print()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim prtdoc As New PrintDocument()
Dim strDefaultPrinter As String = prtdoc.PrinterSettings.PrinterName
Dim strPrinter As [String]
For Each strPrinter In PrinterSettings.InstalledPrinters
ComboBox1.Items.Add(strPrinter)
If strPrinter = strDefaultPrinter Then
ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(strPrinter)
End If
Next strPrinter
End Sub
End Class