undgå sideskift
Hej.. jeg er ved at lave et program som skal skrive små labels på en matrix printer.. Det fungere også fint bortset fra at printeren kører papiret en halv meter frem når den har printet, det er meget uhensigtsmæssigt da labelen kun er 5 cm, faktisk skal den slet ikke kører papiret frem da det er endeløse baner.. papirstørelsen kan ikke indstilles til noget fornuftigt, når man vælger indstillinger på printeren.. Jeg kører windows 2000 med VB.Net.Public Class PrintClass
Private pArrayOfStrings() As String
Private pPrintFont As Font
Private pCurrentLine As Integer = 0
Private pArrayOfStrings_UpperBound As Integer
Public Sub New(ByVal ArrayOfStrings() As String)
Me.New(ArrayOfStrings, New Font("Arial", 14, FontStyle.Bold))
End Sub
Public Sub New(ByVal ArrayOfStrings() As String, ByVal PrintFont As Font)
pArrayOfStrings = ArrayOfStrings
pPrintFont = PrintFont
pArrayOfStrings_UpperBound = pArrayOfStrings.GetUpperBound(0)
Try
Dim PrintDocument As System.Drawing.Printing.PrintDocument = New System.Drawing.Printing.PrintDocument() 'Assumes default printer
AddHandler PrintDocument.PrintPage, New System.Drawing.Printing.PrintPageEventHandler(AddressOf PrintPage)
PrintDocument.Print()
Catch ex As Exception
Dim frmMessage As Form = New Popup("Error occured while printing " & ex.Message & " !")
frmMessage.ShowDialog()
End Try
End Sub
Private Sub PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim LinesPerPage As Single
Dim yPos As Single = 0
Dim Count As Integer = 0
Dim Line As String
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
LinesPerPage = ev.MarginBounds.Height / pPrintFont.GetHeight(ev.Graphics)
' Print each line of the file.
While (Count < LinesPerPage) And (pCurrentLine <= pArrayOfStrings_UpperBound)
Line = pArrayOfStrings(pCurrentLine)
yPos = topMargin + Count * pPrintFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(Line, pPrintFont, Brushes.Black, leftMargin, yPos, New StringFormat())
Count += 1
pCurrentLine += 1
End While
ev.HasMorePages = (pCurrentLine <= pArrayOfStrings_UpperBound)
End Sub
End Class