4 Replies - 7552 Views - Last Post: 07 November 2007 - 11:38 AM Rate Topic: -----

#1 Absenm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-July 07

Printer Control Codes

Posted 31 October 2007 - 02:30 AM

Greetings again. I am steadily progressing on my POS system and have reached the point of messing around with printing. Fortunately I only need to do basic text printing so things shouldn't be too much of a hassel. I researched enough to know that a lot of people are not particularly happy with the way printing working in Visual Basic.Net.

Anyway, I have gotten my printing to work fine except for one issue. I want to send printer control codes. For example a [ESC][V] will cause the sheet cutter to slice. I've been trying simple chr() style prints with no sucess. Does anyone have any suggestions. Below is the code I am using to print. The first one is a class followed by the actual print code.

Public Class myPrinter
	Friend TextToBePrinted As String
	Public Sub prt(ByVal text As String)
		TextToBePrinted = text
		Dim prn As New Printing.PrintDocument
		Using (prn)
			prn.PrinterSettings.PrinterName _
			   = "Generic"
			AddHandler prn.PrintPage, _
			   AddressOf Me.PrintPageHandler
			prn.Print()
			RemoveHandler prn.PrintPage, _
			   AddressOf Me.PrintPageHandler
		End Using
	End Sub
	Private Sub PrintPageHandler(ByVal sender As Object, _
	   ByVal args As Printing.PrintPageEventArgs)
		Dim myFont As New Font("Microsoft San Serif", 10)
		args.Graphics.DrawString(TextToBePrinted, _
		   New Font(myFont, FontStyle.Regular), _
		   Brushes.Black, 50, 50)
	End Sub
End Class



and on button click

	Private Sub ButtCatFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtCatFive.Click
		Dim Print As New myPrinter
		Print.prt("Rehab Tavern" & vbNewLine & "Webster Avenue" [i]control codes[/i])
	End Sub



Any suggestions? I also know I can use the built in print object in VB.net but that seems way too complicated to print a few lines of basic text. Plus, I want instant prints of reciepts with out user being prompted. But I digress, I get it to print all right, just not the control codes. I don't know how to combine a [ESC] with a [V].

Absenm

Is This A Good Question/Topic? 0
  • +

Replies To: Printer Control Codes

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Printer Control Codes

Posted 31 October 2007 - 04:04 AM

Check out the SendKeys Class, this allows you to send key commands to the active window in code. This may do exactly what you're looking for :)
Was This Post Helpful? 0
  • +
  • -

#3 Absenm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-July 07

Re: Printer Control Codes

Posted 31 October 2007 - 06:20 AM

View PostPsychoCoder, on 31 Oct, 2007 - 04:04 AM, said:

Check out the SendKeys Class, this allows you to send key commands to the active window in code. This may do exactly what you're looking for :)



Looks interesting. I'll take a look at it and see if I can use it. But if anyone has any other suggestions I would like to hear them. It is always good to have a few options. Thanks

Absenm

This post has been edited by Absenm: 31 October 2007 - 06:21 AM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Printer Control Codes

Posted 31 October 2007 - 07:16 AM

SendKeys is the only way I'm aware of for sending key codes, but I could be wrong
Was This Post Helpful? 0
  • +
  • -

#5 xander85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-November 07

Re: Printer Control Codes

Posted 07 November 2007 - 11:38 AM

View PostPsychoCoder, on 31 Oct, 2007 - 07:16 AM, said:

SendKeys is the only way I'm aware of for sending key codes, but I could be wrong


Did anyone ever figure out an answer to this? I am looking to do the same thing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1