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(ByVa l sender As Object, ByVal
e As System.Drawing. Printing.PrintP ageEventArgs) Handles
m_PrintDocument .PrintPage
Using string_format As New StringFormat
string_format.A lignment = 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.Regul ar, GraphicsUnit.Po int)
text_size = e.Graphics.Meas ureString(print ableData, the_font)
'MsgBox(text_si ze.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.Heigh t)
e.Graphics.Draw String(printabl eData, 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(ByVa l sender As Object, ByVal
e As System.Drawing. Printing.PrintP ageEventArgs) Handles
m_PrintDocument .PrintPage
Using string_format As New StringFormat
string_format.A lignment = 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.Regul ar, GraphicsUnit.Po int)
text_size = e.Graphics.Meas ureString(print ableData, the_font)
'MsgBox(text_si ze.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.Heigh t)
e.Graphics.Draw String(printabl eData, 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
Comment