Results 1 to 13 of 13

Thread: Sending Textbox Contents to a Thermal Printer.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    Question 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!)

  2. #2
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    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

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    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.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    Question Re: Sending Textbox Contents to a Thermal Printer.

    Quote Originally Posted by bensonsearch View Post
    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!)

  5. #5
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    Question Re: Sending Textbox Contents to a Thermal Printer.

    Quote Originally Posted by bensonsearch View Post
    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
    Code:
    PrintDocument1
    ?
    VS 2017 - Need as much help as you can give (write it all for me!)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    Re: Sending Textbox Contents to a Thermal Printer.

    Quote Originally Posted by callumwk View Post
    Having trouble with the
    Code:
    PrintDocument1
    ?
    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!)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    Re: Sending Textbox Contents to a Thermal Printer.

    Name:  IMG_0022.jpg
Views: 5605
Size:  26.2 KB it is all to the right though?
    VS 2017 - Need as much help as you can give (write it all for me!)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    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!)

  10. #10
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    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

  11. #11
    New Member
    Join Date
    Nov 2018
    Posts
    1

    Resolved Re: Sending Textbox Contents to a Thermal Printer.

    Perfect Dear. Thanks for your efforts.
    Bless you.


    Quote Originally Posted by bensonsearch View Post
    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

  12. #12
    Registered User
    Join Date
    Aug 2015
    Posts
    4

    Re: Sending Textbox Contents to a Thermal Printer.

    Quote Originally Posted by callumwk View Post
    Have no fear! Im an idiot, all works thank you
    Hello Bro, how to fix this ?

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    123

    Re: Sending Textbox Contents to a Thermal Printer.

    Quote Originally Posted by caldeslife View Post
    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
  •  



Click Here to Expand Forum to Full Width