User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 455,970 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,773 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 2742 | Replies: 6
Reply
Join Date: Oct 2007
Posts: 7
Reputation: Rudner D. Diaz is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Rudner D. Diaz Rudner D. Diaz is offline Offline
Newbie Poster

how to print in vb.net

  #1  
Nov 21st, 2007
please help..i need a basic code in printing using vb.net..the scenario is..im 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

rudner
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Posts: 262
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: how to print in vb.net

  #2  
Nov 22nd, 2007
it s very using java script
write javascript for the button u want to print
function printpage()
{
window.print();
}
add attributes to the print button and call javascript using that
Reply With Quote  
Join Date: Sep 2007
Posts: 7
Reputation: bharatsaboo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bharatsaboo bharatsaboo is offline Offline
Newbie Poster

Re: how to print in vb.net

  #3  
Nov 23rd, 2007
how can you use javascript in vb.net
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

regards

bharat
Reply With Quote  
Join Date: Oct 2007
Posts: 7
Reputation: Rudner D. Diaz is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Rudner D. Diaz Rudner D. Diaz is offline Offline
Newbie Poster

Re: how to print in vb.net

  #4  
Nov 23rd, 2007
Thanks for all your replies...

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

thank you
Reply With Quote  
Join Date: Nov 2007
Posts: 3
Reputation: Simran_Jha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Simran_Jha Simran_Jha is offline Offline
Newbie Poster

Solution Re: how to print in vb.net

  #5  
Nov 23rd, 2007
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
Try
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")
Sw.WriteLine("----------------------------------------------------------------------------------------------------------------------------------------------")
For Row = 0 To (myView.RowCount - 1)
Sw.WriteLine()

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")
Sw.WriteLine("------------------------------------------------------------------------------------------------------------------------------------------")
Next
'MessageBox.Show(j)
'MessageBox.Show(i)
Sw.Close()
Fs.Close()
Fs1 = New FileStream("D:\MyFile1.txt", FileMode.Open)
Sr1 = New StreamReader(Fs1)
txtDisplay.Text = Sr1.ReadToEnd
Sr1.Close()
Fs1.Close()

Catch ex As Exception
'MessageBox.Show(ex.Message)
Finally
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
Try
streamToPrint = New StreamReader("D:\MyFile1.txt")
Try
printFont = New Font("Arial", 10)
Dim pd As New Printing.PrintDocument()
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()

Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
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
Else
ev.HasMorePages = False
End If
End Sub
Reply With Quote  
Join Date: Sep 2007
Posts: 5
Reputation: slavedogg is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
slavedogg's Avatar
slavedogg slavedogg is offline Offline
Newbie Poster

Re: how to print in vb.net

  #6  
Nov 28th, 2007
''' 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
Try
Dim printdoc As New PrintDocument
AddHandler printdoc.PrintPage, AddressOf Me.printtext
printdoc.Print()
Catch ex As Exception
MessageBox.Show("Sorry there is a problem printing", ex.ToString())
End Try
End Sub
_______
|} {} gg|
----------
Reply With Quote  
Join Date: Aug 2007
Posts: 16
Reputation: jaytheguru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jaytheguru jaytheguru is offline Offline
Newbie Poster

Re: how to print in vb.net

  #7  
Mar 26th, 2008
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 9:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC