.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Printing a Invoice using Dotmatrix printer in a c# windows appliaction

Posted By: Ullas     Posted Date: March 22, 2012    Points:5   Category :Windows Application
I am developing a windows application project for a super market.Now i want to create a sales bill .I have a datagridview with header columns ITEM NAME,QTY,RATE,AMOUNT etc... I can enter the item name ,qty rate and mount on the gridview.Now what i want is to print these contents on the gridview through a dotmatrix printer to make printing faster.The bill format which i expect to be printed out is should be like what i have shown below

No/10,Ammankovil street

Bill NO : 1 Date: 12/12/2012
Sl.No Item Name Qty Rate Amount
1 xyz 2 120.00 240.00
2 abc 1 500.00 500.00
3 asd 3 100.00 300.00
Total: 1040.00

Please provide me the code to do this.I do not want a printdialog to appear first and then go for printing as this will be tedious process in a crowdy supermarket where continous bill printing is to be made

Thanks in advance


Author: Mahesh             
Posted Date: March 29, 2012     Points: 20   

You can use following code, changes needs to be done in code below as per u r requirement...,

Private Sub cmdPrint_Click()
Dim intLineCtr As Integer
Dim intPageCtr As Integer
Dim intX As Integer
Dim strCustFileName As String
Dim strBackSlash As String
Dim intCustFileNbr As Integer

Dim strFirstName As String
Dim strLastName As String
Dim strAddr As String
Dim strCity As String
Dim strState As String
Dim strZip As String

Const intLINE_START_POS As Integer = 6
Const intLINES_PER_PAGE As Integer = 60

' Have the user make sure his/her printer is ready ...
If MsgBox("Make sure your printer is on-line and " _
& "loaded with paper.", vbOKCancel, "Check Printer") = vbCancel _
Exit Sub
End If

' Set the printer font to Courier, if available (otherwise, we would be
' relying on the default font for the Windows printer, which may or
' may not be set to an appropriate font) ...

For intX = 0 To Printer.FontCount - 1
If Printer.Fonts(intX) Like "Courier*" Then
Printer.FontName = Printer.Fonts(intX)
Exit For
End If

Printer.FontSize = 10

' initialize report variables ...
intPageCtr = 0
intLineCtr = 99 ' initialize line counter to an arbitrarily high number

' to force the first page break
' prepare file name & number
strBackSlash = IIf(Right$(App.Path, 1) = "\", "", "\")
strCustFileName = App.Path & strBackSlash & "customer.txt"
intCustFileNbr = FreeFile

' open the input file
Open strCustFileName For Input As #intCustFileNbr

' read and print all the records in the input file
Do Until EOF(intCustFileNbr)

' read a record from the input file and store the fields there into VB variables
Input #intCustFileNbr, strLastName, strFirstName, strAddr, strCity, strState, strZip

' if the number of lines printed so far exceeds the maximum number of lines
' allowed on a page, invoke the PrintHeadings subroutine to do a page break
If intLineCtr > intLINES_PER_PAGE Then
GoSub PrintHeadings
End If

' print a line of data
Printer.Print Tab(intLINE_START_POS); _
strFirstName & " " & strLastName; _
Tab(21 + intLINE_START_POS); _
strAddr; _
Tab(48 + intLINE_START_POS); _
strCity; _
Tab(72 + intLINE_START_POS); _
strState; _
Tab(76 + intLINE_START_POS); _

' increment the line count
intLineCtr = intLineCtr + 1


' close the input file
Close #intCustFileNbr

' Important! When done, the EndDoc method of the Printer object must be invoked.
' The EndDoc method terminates a print operation sent to the Printer object,
' releasing the document to the print device or spooler.


Exit Sub

' internal subroutine to print report headings
' If we are about to print any page other than the first, invoke the NewPage
' method to perform a page break. The NewPage method advances to the next
' printer page and resets the print position to the upper-left corner of the
' new page.

If intPageCtr > 0 Then
End If

' increment the page counter
intPageCtr = intPageCtr + 1

' Print 4 blank lines, which provides a for top margin. These four lines do NOT
' count toward the limit of 60 lines.


' Print the main headings
Printer.Print Tab(intLINE_START_POS); _
"Print Date: "; _
Format$(Date, "mm/dd/yy"); _
Tab(intLINE_START_POS + 31); _
Tab(intLINE_START_POS + 73); _
"Page:"; _
Format$(intPageCtr, "@@@")
Printer.Print Tab(intLINE_START_POS); _
"Print Time: "; _
Format$(Time, "hh:nn:ss"); _
Tab(intLINE_START_POS + 33); _


' Print the column headings
Printer.Print Tab(intLINE_START_POS); _
Tab(21 + intLINE_START_POS); _
Tab(48 + intLINE_START_POS); _
"CITY"; _
Tab(72 + intLINE_START_POS); _
"ST"; _
Tab(76 + intLINE_START_POS); _

Printer.Print Tab(intLINE_START_POS); _
"-------------"; _
Tab(21 + intLINE_START_POS); _
"-------"; _
Tab(48 + intLINE_START_POS); _
"----"; _
Tab(72 + intLINE_START_POS); _
"--"; _
Tab(76 + intLINE_START_POS); _


' reset the line counter to reflect the number of lines that have now
' been printed on the new page.
intLineCtr = 6


End Sub

Hope this helps...

Thanks & Regards,

Author: ksubbareddy             
Posted Date: April 05, 2012     Points: 20   

hi ...plz send above project in the c# - language

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend