G
Glenn
I am writing a program for field work that will use a receipt
printer. I need to be able to adjust the page settings prior to
printing depending on how much needs to be printed. I have been able
to print to this printer but cannot figure out how to overwrite the
page settings.
Below is the code so far:
Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs) Handles
m_PrintDocument.PrintPage
Using string_format As New StringFormat
string_format.Alignment = StringAlignment.Near
Dim text_size As SizeF
Dim font_size As Integer = 12
Dim font_name As String = "Times New Roman"
Using the_font As New Font(font_name, font_size,
FontStyle.Regular, GraphicsUnit.Point)
text_size = e.Graphics.MeasureString(printableData, the_font)
'MsgBox(text_size.Height)
'Dim layout_rect As RectangleF = New RectangleF
(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width,
e.MarginBounds.Height)
Dim layout_rect As RectangleF = New RectangleF
(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width,
text_size.Height)
e.Graphics.DrawString(printableData, the_font, Brushes.Black,
layout_rect, string_format)
End Using
End Using
e.HasMorePages = False
End Sub
printableData above is a function that returns the formated text.
I think that somehow I need to either change the e.pagesettings,
e.pagebounds, or something else, but everything I have tried has not
worked. When trying to change e.pagesettings or e.pagebounds, I get
the following error message:
expression is a value and therefore cannot be the target of an
assignment
printer. I need to be able to adjust the page settings prior to
printing depending on how much needs to be printed. I have been able
to print to this printer but cannot figure out how to overwrite the
page settings.
Below is the code so far:
Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs) Handles
m_PrintDocument.PrintPage
Using string_format As New StringFormat
string_format.Alignment = StringAlignment.Near
Dim text_size As SizeF
Dim font_size As Integer = 12
Dim font_name As String = "Times New Roman"
Using the_font As New Font(font_name, font_size,
FontStyle.Regular, GraphicsUnit.Point)
text_size = e.Graphics.MeasureString(printableData, the_font)
'MsgBox(text_size.Height)
'Dim layout_rect As RectangleF = New RectangleF
(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width,
e.MarginBounds.Height)
Dim layout_rect As RectangleF = New RectangleF
(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width,
text_size.Height)
e.Graphics.DrawString(printableData, the_font, Brushes.Black,
layout_rect, string_format)
End Using
End Using
e.HasMorePages = False
End Sub
printableData above is a function that returns the formated text.
I think that somehow I need to either change the e.pagesettings,
e.pagebounds, or something else, but everything I have tried has not
worked. When trying to change e.pagesettings or e.pagebounds, I get
the following error message:
expression is a value and therefore cannot be the target of an
assignment