-
Print direct to LPT1 on Vb2005
Hi,
Any other way to print direct to LPT1 without using printdocument control.
Please provided some basic example??

-
You could talk directly to the printer driver... if you are a masochist :-)
Straigth from .NET, the PrintDocument class is the thing. The PrintDocument control is only a wrapper around the PrintDocument class to enable features such as PrintPreview.
Depending on what you need to print however, and also depending on what is installed on your users machines, you can delegate the printout to an external application.
I often use Word or Excel from my .NET code to print reports and forms. This is completely invisible to the user who thinks that my application is doing the job.
If the data comes from a database, there are a few report generators available.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
thank you for your info and reply,actually i want to print the text or code number to the printer port (LPT1)
my code is like this:-
Code:
Printer.Print "{D0450,0320,0450|}"
Printer.Print "{T10C51|}"
Printer.Print "{AX;+090,+000,-00|}"
Printer.Print "{AY;+00,0|}"
Printer.Print "{AY;+00,1|}"
Printer.Print "{C|}"
Printer.Print "{XB00;0040,0057,5,3,02,0,0100,-0000000000,018,0,00|}"
Printer.Print "{PV01;0035,0050,0025,0034,A,-006,00,B|}"
Printer.Print "{PV02;0085,0228,0022,0047,B,-000,00,B|}"
Printer.Print "{PV03;0085,0260,0021,0033,A,-005,00,B|}"
Printer.Print "{PV04;0085,0290,0021,0033,A,-005,00,B|}"
Printer.Print "{PV05;0085,0322,0021,0033,A,-005,00,B|}"
Printer.Print "{PV06;0085,0354,0021,0033,A,-005,00,B|}"
Printer.Print "{PC07;0039,0185,05,05,G,-01,00,B|}"
Printer.Print "{PC08;0269,0185,05,05,G,-01,00,B|}"
Printer.Print "{LC;0049,0180,0267,0180,0,2|}"
Printer.Print "{RB00;202500119900|}"
Printer.Print "{RV01;2025001199001|}"
Printer.Print "{RV02;RM 199.00|}"
Printer.Print "{RV03;250016|}"
Printer.Print "{RV04;2 K3|}"
Printer.Print "{RV05;110600|}"
Printer.Print "{RV06;-|}"
Printer.Print "{RC07;v|}"
Printer.Print "{RC08;v|}"
Printer.Print "{XS;I,0002,0001C4100|}"
Printer.EndDoc
Last edited by Hack; 07-21-2011 at 06:58 AM.
Reason: Added Code Tags
-
That looks very much like VB6...what version of Visual Basic are you using?
-
yes..is a vb6 but on vb 2005 i don't know how to send print to LPT1?
-
The way to print has completely changed in .NET. It is a little more tricky.
The VB6 way of printing was from 20 years ago, in a time where printing was less sophisticated is today, when printouts looked more like old typewritten sheets than the multi-fonts, color and full of images documents when tend to print today. The Printer object was not sufficient for today's needs.
In .NET, Microsoft gave us a more complete control over the printer. Who says more complete means more complex.
You have 2 choices. Or you use a third party tool as stated in a previous post, which is what most programmers do. Or you take full control, but then have to work for it.
You use a PrintDocument (pd in the following code) to setup the printer:
Code:
pd.PrinterSettings.PrinterName = "HP DeskJet 5500"
With pd.DefaultPageSettings
.Landscape = paysage
.Margins.Left = 25
.Margins.Top = 25
End With
pd.Print()
The Print method does not do the job, it simply triggers the PrintPage event of the PrintDocument object. You write your actual printing code in this event.
What is tricky is that this event will be called once for each page, so you have to check on each call whether there are still pages to be printed. The ev parameter of the event is the object you use to get information about the printing environment. The ev.Graphics property lets you control what goes to the printer.
The following code prints all the strings in an array called lines. Printing in a loop from an array makes things simpler.
Code:
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Handles pd.PrintPage
Static currentLine As Integer = 0
Dim lastLine As Integer = lines.GetUpperBound(0)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
' Print each line of the file.
While count < linesPerPage
If currentLine > lastLine Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(lines(currentLine), printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
count += 1
currentLine += 1
End While
' If more lines exist, print another page.
If currentLine < lastLine Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
You can simply fill the lines array with your data, or replace the code that deals with lines to handle what you need to print. This might look something like this:
Code:
yPos = topMargin
ev.Graphics.DrawString("{D0450,0320,0450|}", printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
yPos += count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString("{T10C51|}", printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
yPos += count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString("{AX;+090,+000,-00|}", printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
...
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
Thank Jbourgeois for your info, but why this lines got problem 'lines.GetUpperBound(0)' ??
-
Define "problems" - are you getting an error?
If so, what is it?
-
name 'lines' is not declared
-
 Originally Posted by JBourgeois
The following code prints all the strings in an array called lines.
He doesn't show the declaration, but this is where it is coming from.
-
you know what is the problem ? pls help..
-
I sent you a straight copy of one of my methods to show you the concept. You will have to adjust it according to your own data. That is why I sent you the second piece of code which you might prefer to use.
The lines array is declared and filled outside of the method, so you do not see the declaration here. GetUpperBound enables me to know its size, since it change everytime I use the routine.
If you want to go the array route, it's declaration and initialisation in you case would be something like the following, where x is the number of lines minus 1:
Code:
Dim lines(x) As String
lines(0) = "{D0450,0320,0450|}"
lines(1) = "{T10C51|}"
lines(2) = "{AX;+090,+000,-00|}"
' ... and so on
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
Thank JBourgeois i know it..
Similar Threads
-
Replies: 2
Last Post: 03-06-2010, 03:19 AM
-
By oranged in forum VB Classic
Replies: 2
Last Post: 07-19-2006, 06:50 AM
-
By malikmehmood in forum Database
Replies: 0
Last Post: 11-20-2000, 06:12 AM
-
Replies: 2
Last Post: 03-24-2000, 02:05 PM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|