please help..i need a basic code in printing using scenario going to print a delivery reciept..the data will be came from my tables...i need the code on printing..basic printing..
thanks in advance


it s very using java script
write javascript for the button u want to print
function printpage()
add attributes to the print button and call javascript using that

how can you use javascript in
it is only useful for asp or web based applications

i think you should use crystal reports or download the visual studio power packs which allows you to print forms



Thanks for all your replies...

is there any way on how to print in without using crystal or any third party?...just basic code in printing..

thank you

Here is code for Printing in VB.Net which we r using in our Project.
Its printing the document but not in tabular format which we require.
So try this code its working , but if u find any solution to print in receipt format.Plz let me knw.

Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
            Fs = New FileStream("D:\MyFile1.txt", FileMode.Create)
                     Sw = New StreamWriter(Fs)
            Dim Row As Integer
            'Row = myView.RowCount - 1
            Sw.WriteLine("{0,5}{1,15}{2,20}{3,20}{4,20}", "SUPPLIER_ID", "SUPPLIER_NAME", "SUPPLIER_ADDRESS", "CONTACT_PERSON", "CONTACT_NUMBER")
            For Row = 0 To (myView.RowCount - 1)

                Sw.WriteLine("{0,5}{1,25}{2,35}{3,45}", ((myView.Item("SUPPLIER_ID", Row)).Value), ((myView.Item("SUPPLIER_NAME", Row)).Value), ((myView.Item("SUPPLIER_ADDRESS", Row)).Value), ((myView.Item("CONTACT_PERSON", Row)).Value)) ', "CONTACT_NUMBER")
            Fs1 = New FileStream("D:\MyFile1.txt", FileMode.Open)
            Sr1 = New StreamReader(Fs1)
            txtDisplay.Text = Sr1.ReadToEnd

        Catch ex As Exception
            Sw = Nothing
            Fs = Nothing
        End Try
    End Sub

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
            streamToPrint = New StreamReader("D:\MyFile1.txt")
                printFont = New Font("Arial", 10)
                Dim pd As New Printing.PrintDocument()
                AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage

            End Try
        Catch ex As Exception
        End Try

    End Sub

    Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.PrintPageEventArgs)
        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
        Dim line As String = Nothing

        ' Calculate the number of lines per page.
        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

        ' Print each line of the file.
        While count < linesPerPage
            line = streamToPrint.ReadLine()
            If line Is Nothing Then
                Exit While
            End If
            yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
            ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
            count += 1
        End While

        ' If more lines exist, print another page.
        If Not (line Is Nothing) Then
            ev.HasMorePages = True
            ev.HasMorePages = False
        End If
    End Sub

Edited 3 Years Ago by mike_2000_17: Fixed formatting

''' at the very top of the form
Imports System.Drawing.Printing

''' new sub procedure
Private Sub printtext(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
ev.Graphics.DrawString(lblQ2.Text, New Font("arial", 11, FontStyle.Regular), Brushes.Black, 120, 120)
ev.HasMorePages = False
End Sub

''' button event
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
Dim printdoc As New PrintDocument
AddHandler printdoc.PrintPage, AddressOf Me.printtext
Catch ex As Exception
MessageBox.Show("Sorry there is a problem printing", ex.ToString())
End Try
End Sub

This converts the data binded into the datagrid into a text file and then prints it out. I am more interested in printing the data binded into the grid directly to the printer. I will post a solution once I find one.

i did not make a print button. using your codes..
and its not functioning will.there are some errors..

Create a Print Button or File>Print tab
Then, at the bottom of the toolbox, Expand the VB PowerPack
Double Click "PrintForm1"

This Creates a Pane at the Bottom with "PrintForm1"

Double Click Your "Print" button and in the code write

Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Prints the form

End Sub

This article has been dead for over six months. Start a new discussion instead.