Printing with vb.net (Urgent)
-
I have to create a Entry Ticket & then Print it Now How to Print the VB.net forms with all controls on it 1 Logo (PictureBox) 2. Labels of Name & Address Etc 3. Barcode is also on my entry ticket form Except the Print Button on it. Waiting for all early replies Thanks in advance for this esteemed help Hema Chaudhry
-
I have to create a Entry Ticket & then Print it Now How to Print the VB.net forms with all controls on it 1 Logo (PictureBox) 2. Labels of Name & Address Etc 3. Barcode is also on my entry ticket form Except the Print Button on it. Waiting for all early replies Thanks in advance for this esteemed help Hema Chaudhry
Easy! first of all make print button property visible=false.then press F5 to run it. when form get loaded press prt screen(print screen) button of ur keyboard.then paste it in paint application.now from selection tool select the form and copy it.after copying successfully open ms word document and paste it.then take out print after adjusting form image on page best of luck Hema. bye!! Uttam if I helped u any way, mail me at trickyuk001@rediffmail.com try to be the best... whereever you go, -- modified at 2:54 Monday 12th December, 2005
-
Easy! first of all make print button property visible=false.then press F5 to run it. when form get loaded press prt screen(print screen) button of ur keyboard.then paste it in paint application.now from selection tool select the form and copy it.after copying successfully open ms word document and paste it.then take out print after adjusting form image on page best of luck Hema. bye!! Uttam if I helped u any way, mail me at trickyuk001@rediffmail.com try to be the best... whereever you go, -- modified at 2:54 Monday 12th December, 2005
Thanks for your Prompt Reply, But Dear , I want to print the the form from the VB.net Code itself Not from the Paint . Means My application has the option print preview & print etc . Then CLick on Print will print the desired form. AnyWay Thanks Plz reply If you know about that. Thansk in advance Hema Chaudhry
-
Thanks for your Prompt Reply, But Dear , I want to print the the form from the VB.net Code itself Not from the Paint . Means My application has the option print preview & print etc . Then CLick on Print will print the desired form. AnyWay Thanks Plz reply If you know about that. Thansk in advance Hema Chaudhry
ok Madam, I m here 2 help u out.I have an idea.first u save ur form as a picture.then using code u can print out ur picture which will be ur form.try this code to print out.use print.picture method to take print out picture.
dim sngLeft as single dim sngTop as single sngLeft = (prn.scalewidth - prn.scalex(pic.width,vbhimetric, prn.scalemode)) / 2 sngTop = (prn.scaleheight - prn.scaley(pic.height, vbhimetric, prn.scalemode)) / 2 prn.Paintpicture pic, sngLeft, sngTop
if u don't get result Try this link follows. http://www.vb-helper.com/howto_net_print_form_image.html Hope so u'll get ur result.if this help you mail me at trickyuk001@rediffmail.com.& try to help me in solving my problem. Thanking you Uttam Kumar mumbai,convonix.inc try to be the best... whereever you go, -- modified at 5:24 Monday 12th December, 2005 -
I have to create a Entry Ticket & then Print it Now How to Print the VB.net forms with all controls on it 1 Logo (PictureBox) 2. Labels of Name & Address Etc 3. Barcode is also on my entry ticket form Except the Print Button on it. Waiting for all early replies Thanks in advance for this esteemed help Hema Chaudhry
The formally correct solution is probably the best one although is a bit more complex. But not too much. You have better to use a PrintDocument class. There's plenty of documentation and samples on MSDN and here as well. To summarize: 1) Create a desgin time a printdocument in the form (i.e. called pDoc) 2) Double click on it to open the editor in the printing function 3) Write the code to print your data (***) 4) From the button invoke the
pDoc.Print
method. (***) I'm not able to write the full code you need but it should be something with:e.graphics.drawstring
for each text you want to printe.graphics.drawimage
for each image you want to print. Here's an example from the documentationPublic Class PrintingExample
Inherits System.Windows.Forms.Form
Private components As System.ComponentModel.Container
Private printButton As System.Windows.Forms.Button
Private printFont As Font
Private streamToPrint As StreamReaderPublic Sub New() ' The Windows Forms Designer requires the following call. InitializeComponent() End Sub ' The Click event is raised when the user clicks the Print button. Private Sub printButton\_Click(sender As Object, e As EventArgs) Try streamToPrint = New StreamReader("C:\\My Documents\\MyFile.txt") Try printFont = New Font("Arial", 10) Dim pd As New 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 ' The PrintPage event is raised for each page to be printed. Private Sub pd\_PrintPage(sender As Object, ev As 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
-
The formally correct solution is probably the best one although is a bit more complex. But not too much. You have better to use a PrintDocument class. There's plenty of documentation and samples on MSDN and here as well. To summarize: 1) Create a desgin time a printdocument in the form (i.e. called pDoc) 2) Double click on it to open the editor in the printing function 3) Write the code to print your data (***) 4) From the button invoke the
pDoc.Print
method. (***) I'm not able to write the full code you need but it should be something with:e.graphics.drawstring
for each text you want to printe.graphics.drawimage
for each image you want to print. Here's an example from the documentationPublic Class PrintingExample
Inherits System.Windows.Forms.Form
Private components As System.ComponentModel.Container
Private printButton As System.Windows.Forms.Button
Private printFont As Font
Private streamToPrint As StreamReaderPublic Sub New() ' The Windows Forms Designer requires the following call. InitializeComponent() End Sub ' The Click event is raised when the user clicks the Print button. Private Sub printButton\_Click(sender As Object, e As EventArgs) Try streamToPrint = New StreamReader("C:\\My Documents\\MyFile.txt") Try printFont = New Font("Arial", 10) Dim pd As New 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 ' The PrintPage event is raised for each page to be printed. Private Sub pd\_PrintPage(sender As Object, ev As 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