Sending Textbox Contents to a Thermal Printer.
Hey everyone,
I am looking to have the contents of a text box sent to a thermal printer on a button press. I can't seem to find anything of much use on the web. I would try adapting some code from somewhere else but my VB knowledge is very small.
Thanks for the help and sorry for being so vage, I'll answer any questions if I've missed anything out.
Re: Sending Textbox Contents to a Thermal Printer.
Hi, I will start out by saying that printing to a thermal printer is the same as printing to ANY printer. try looking done the road of printing a string, if you get stuck let me know (I use thermal printers on a more than daily basis with VB.Net).
Re: Sending Textbox Contents to a Thermal Printer.
I think your making a POS application.
Additional References:
VB Forum: VB Forums Thermal-printer-printing
Microsoft Support: Send Raw Data to a printer.
Crystal Reports Problem: vb.net-problem-printing-receipt-thermal in Crystal Reports
Note: I made similar project(s) using VB 6.0 and not .NET.
Re: Sending Textbox Contents to a Thermal Printer.
Quote:
Originally Posted by
bensonsearch
Hi, I will start out by saying that printing to a thermal printer is the same as printing to ANY printer. try looking done the road of printing a string, if you get stuck let me know (I use thermal printers on a more than daily basis with VB.Net).
Okay thanks, it is now set as my default printer. I am know looking for a simple code that will let me send the (rich)textbox contents to the printer. Im not worried about formatting or spacing because I should be able to correct for that in the lines of text it will print. I just need something like textbox1.text = doprint or something that easy, if such a thing exists..
Thanks :)
Re: Sending Textbox Contents to a Thermal Printer.
well the easiest way is to add a print document control and some code, this is on a form with a button. for note I have made POS systems on .Net platform and it is currently my full time work, I use a custom class to add extra control, I can not find the tutorial but am happy to share the class if you go down that road.
Code:
Public Class Form1
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static intCurrentChar As Int32
Dim font As New Font("Verdana", 8)
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left
marginTop = .Margins.Top
End With
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
End Class
Re: Sending Textbox Contents to a Thermal Printer.
Quote:
Originally Posted by
bensonsearch
well the easiest way is to add a print document control and some code, this is on a form with a button. for note I have made POS systems on .Net platform and it is currently my full time work, I use a custom class to add extra control, I can not find the tutorial but am happy to share the class if you go down that road.
Code:
Public Class Form1
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static intCurrentChar As Int32
Dim font As New Font("Verdana", 8)
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left
marginTop = .Margins.Top
End With
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
End Class
Having trouble with the ?
Re: Sending Textbox Contents to a Thermal Printer.
Quote:
Originally Posted by
callumwk
Having trouble with the
?
Have no fear! Im an idiot, all works thank you :)
1 Attachment(s)
Re: Sending Textbox Contents to a Thermal Printer.
Attachment 114221 it is all to the right though?
Re: Sending Textbox Contents to a Thermal Printer.
Dont worry fixed that too ;)
Re: Sending Textbox Contents to a Thermal Printer.
hahaha glad you fixed it :)
also you may want to look into using an equal width font, that way all letters take the same space. I think i use Lucidia console or something like that
Re: Sending Textbox Contents to a Thermal Printer.
Perfect Dear. Thanks for your efforts.
Bless you.
Quote:
Originally Posted by
bensonsearch
well the easiest way is to add a print document control and some code, this is on a form with a button. for note I have made POS systems on .Net platform and it is currently my full time work, I use a custom class to add extra control, I can not find the tutorial but am happy to share the class if you go down that road.
Code:
Public Class Form1
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static intCurrentChar As Int32
Dim font As New Font("Verdana", 8)
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left
marginTop = .Margins.Top
End With
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
End Class
Re: Sending Textbox Contents to a Thermal Printer.
Quote:
Originally Posted by
callumwk
Have no fear! Im an idiot, all works thank you :)
Hello Bro, how to fix this ?
Re: Sending Textbox Contents to a Thermal Printer.
Quote:
Originally Posted by
caldeslife
Hello Bro, how to fix this ?
That was 6 years ago. I've no idea.