-
May 14th, 2014, 05:24 PM
#1
Thread Starter
Lively Member
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.
VS 2017 - Need as much help as you can give (write it all for me!)
-
May 15th, 2014, 04:14 AM
#2
Fanatic Member
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).
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
May 15th, 2014, 04:17 AM
#3
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.
-
May 16th, 2014, 04:56 PM
#4
Thread Starter
Lively Member
Re: Sending Textbox Contents to a Thermal Printer.
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
VS 2017 - Need as much help as you can give (write it all for me!)
-
May 16th, 2014, 05:23 PM
#5
Fanatic Member
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
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
May 16th, 2014, 05:37 PM
#6
Thread Starter
Lively Member
Re: Sending Textbox Contents to a Thermal Printer.
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 ?
VS 2017 - Need as much help as you can give (write it all for me!)
-
May 16th, 2014, 05:41 PM
#7
Thread Starter
Lively Member
Re: Sending Textbox Contents to a Thermal Printer.
Originally Posted by callumwk
Having trouble with the ?
Have no fear! Im an idiot, all works thank you
VS 2017 - Need as much help as you can give (write it all for me!)
-
May 16th, 2014, 05:44 PM
#8
Thread Starter
Lively Member
Re: Sending Textbox Contents to a Thermal Printer.
it is all to the right though?
VS 2017 - Need as much help as you can give (write it all for me!)
-
May 16th, 2014, 05:46 PM
#9
Thread Starter
Lively Member
Re: Sending Textbox Contents to a Thermal Printer.
Dont worry fixed that too
VS 2017 - Need as much help as you can give (write it all for me!)
-
May 16th, 2014, 11:18 PM
#10
Fanatic Member
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
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Nov 2nd, 2018, 05:15 AM
#11
New Member
Re: Sending Textbox Contents to a Thermal Printer.
Perfect Dear. Thanks for your efforts.
Bless you.
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
-
Jan 31st, 2020, 01:27 AM
#12
Registered User
Re: Sending Textbox Contents to a Thermal Printer.
Originally Posted by callumwk
Have no fear! Im an idiot, all works thank you
Hello Bro, how to fix this ?
-
Jan 31st, 2020, 11:28 AM
#13
Thread Starter
Lively Member
Re: Sending Textbox Contents to a Thermal Printer.
Originally Posted by caldeslife
Hello Bro, how to fix this ?
That was 6 years ago. I've no idea.
Last edited by callumwk; Jan 31st, 2020 at 11:29 AM.
Reason: Can't do simple maths.
VS 2017 - Need as much help as you can give (write it all for me!)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|