Click here to Skip to main content
15,915,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to make a report document in vb.net but i cant manage to create a table in the document. Im new in printing document in vb and im using the basic codes on printing.



I want the printed document will look like this

1 — imgbb.com[^]

What I have tried:

This is what i tried:

2 — imgbb.com[^]

VB
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

      Dim ReportFont As Font = New Drawing.Font("Bebas Neue", 16)
      Dim ReportBodyFont As Font = New Drawing.Font("Bebas Neue", 6)

      'Report'

      e.Graphics.DrawImage(My.Resources.logodgn, 580, 10, 220, 50)
      e.Graphics.DrawString("SERVICE COMPLETION REPORT", ReportFont, Brushes.Red, 220, 40)
      e.Graphics.DrawString("Date: ", ReportFont, Brushes.Black, 450, 90)
      e.Graphics.DrawString(datePicker.Text, ReportFont, Brushes.Blue, 510, 90)
      e.Graphics.DrawString("Client:   ", ReportFont, Brushes.Black, 50, 130)
      e.Graphics.DrawString(clientNameText.Text, ReportFont, Brushes.Blue, 120, 130)
      e.Graphics.DrawString("Time Started: ", ReportFont, Brushes.Black, 550, 130)
      e.Graphics.DrawString(timeStartedText.Text, ReportFont, Brushes.Blue, 680, 130)
      e.Graphics.DrawString("Contact Person:   ", ReportFont, Brushes.Black, 50, 160)
      e.Graphics.DrawString(cPersonText.Text, ReportFont, Brushes.Blue, 210, 160)
      e.Graphics.DrawString("Time Ended: ", ReportFont, Brushes.Black, 550, 160)
      e.Graphics.DrawString(timeEndedText.Text, ReportFont, Brushes.Blue, 680, 160)
      ''
      e.Graphics.DrawString("Dear Sir/Madame: ", ReportFont, Brushes.Black, 50, 210)
      e.Graphics.DrawString("Please acknowledge completion of service rendered.", ReportFont, Brushes.Black, 50, 250)
      e.Graphics.DrawString("Kindly see this presented form for particulars of areas covered and ", ReportFont, Brushes.Black, 50, 280)
      e.Graphics.DrawString("done by our service and use of our technology.", ReportFont, Brushes.Black, 50, 310)
      ''
      e.Graphics.DrawString("Doclogging", ReportFont, Brushes.Black, 50, 360)
      e.Graphics.DrawString("Quantity", ReportFont, Brushes.Black, 220, 360)
      e.Graphics.DrawString("Clogged", ReportFont, Brushes.Black, 330, 360)
      e.Graphics.DrawString("Findings/Remarks", ReportFont, Brushes.Black, 470, 360)
      ''
      e.Graphics.DrawString("Floor Drain", ReportFont, Brushes.Green, 50, 400)
      e.Graphics.DrawString(fldQuantityText.Text, ReportFont, Brushes.Blue, 220, 400)
      e.Graphics.DrawString(fldClText.Text, ReportFont, Brushes.Blue, 330, 400)
      e.Graphics.DrawString(fldFinRecText.Text, ReportFont, Brushes.Blue, 470, 400)
      ''
      e.Graphics.DrawString("Grease Trap", ReportFont, Brushes.Green, 50, 430)
      e.Graphics.DrawString(grtQuantityText.Text, ReportFont, Brushes.Blue, 220, 430)
      e.Graphics.DrawString(grtClText.Text, ReportFont, Brushes.Blue, 330, 430)
      e.Graphics.DrawString(grtFinRecText.Text, ReportFont, Brushes.Blue, 470, 430)
      ''
      e.Graphics.DrawString("Clean Out", ReportFont, Brushes.Green, 50, 460)
      e.Graphics.DrawString(coQuantityText.Text, ReportFont, Brushes.Blue, 220, 460)
      e.Graphics.DrawString(coClText.Text, ReportFont, Brushes.Blue, 330, 460)
      e.Graphics.DrawString(coFinRecText.Text, ReportFont, Brushes.Blue, 470, 460)
      ''
      e.Graphics.DrawString("Kitchen Cleaning", ReportFont, Brushes.Black, 50, 490)
      ''
      e.Graphics.DrawString("Range", ReportFont, Brushes.Green, 50, 520)
      e.Graphics.DrawString(rngQuantityText.Text, ReportFont, Brushes.Blue, 220, 520)
      e.Graphics.DrawString(rngClText.Text, ReportFont, Brushes.Blue, 330, 520)
      e.Graphics.DrawString(rngFinRecText.Text, ReportFont, Brushes.Blue, 470, 520)
      ''
      e.Graphics.DrawString("Oven", ReportFont, Brushes.Green, 50, 550)
      e.Graphics.DrawString(ovnQuantityText.Text, ReportFont, Brushes.Blue, 220, 550)
      e.Graphics.DrawString(ovnClText.Text, ReportFont, Brushes.Blue, 330, 550)
      e.Graphics.DrawString(ovnFinRecText.Text, ReportFont, Brushes.Blue, 470, 550)
      ''
      e.Graphics.DrawString("Grill", ReportFont, Brushes.Green, 50, 580)
      e.Graphics.DrawString(grlQuantityText.Text, ReportFont, Brushes.Blue, 220, 580)
      e.Graphics.DrawString(grlClText.Text, ReportFont, Brushes.Blue, 330, 580)
      e.Graphics.DrawString(grlFinRecText.Text, ReportFont, Brushes.Blue, 470, 580)
      ''
      e.Graphics.DrawString("Deep-fryer", ReportFont, Brushes.Green, 50, 610)
      e.Graphics.DrawString(dpfQuantityText.Text, ReportFont, Brushes.Blue, 220, 610)
      e.Graphics.DrawString(dpfClText.Text, ReportFont, Brushes.Blue, 330, 610)
      e.Graphics.DrawString(dpfFinRecText.Text, ReportFont, Brushes.Blue, 470, 610)
      ''
      e.Graphics.DrawString("Hoods", ReportFont, Brushes.Green, 50, 640)
      e.Graphics.DrawString(hdsQuantityText.Text, ReportFont, Brushes.Blue, 220, 640)
      e.Graphics.DrawString(hdsClText.Text, ReportFont, Brushes.Blue, 330, 640)
      e.Graphics.DrawString(hdsFinRecText.Text, ReportFont, Brushes.Blue, 470, 640)
      ''
      e.Graphics.DrawString("D&G Pacific Personnel", ReportFont, Brushes.Black, 300, 700)
      e.Graphics.DrawString("1. " + pCB1.Text, ReportFont, Brushes.Blue, 50, 730)
      e.Graphics.DrawString("2. " + pCB2.Text, ReportFont, Brushes.Blue, 50, 760)
      e.Graphics.DrawString("3. " + pCB3.Text, ReportFont, Brushes.Blue, 50, 790)
      e.Graphics.DrawString("4. " + pCB4.Text, ReportFont, Brushes.Blue, 470, 730)
      e.Graphics.DrawString("5. " + pCB5.Text, ReportFont, Brushes.Blue, 470, 760)
      e.Graphics.DrawString("6. " + pCB6.Text, ReportFont, Brushes.Blue, 470, 790)
      ''
      e.Graphics.DrawString("Service Rendered:", ReportFont, Brushes.Black, 50, 830)
      e.Graphics.DrawString("Client Remarks", ReportFont, Brushes.Black, 350, 830)
      e.Graphics.DrawString("Service Grade", ReportFont, Brushes.Black, 650, 830)
      'Service Rendered'
      e.Graphics.DrawString("▢ Kitchen Cleaning", ReportFont, Brushes.Black, 50, 860)
      e.Graphics.DrawString("▢ De-clogging", ReportFont, Brushes.Black, 50, 890)
      e.Graphics.DrawString("▢ Duct Cleaning", ReportFont, Brushes.Black, 50, 920)
      e.Graphics.DrawString("Other", ReportFont, Brushes.Black, 50, 950)
      e.Graphics.DrawString("_____________", ReportFont, Brushes.Black, 50, 980)
      'Client Remarks'
      e.Graphics.DrawString("_____________________", ReportFont, Brushes.Black, 275, 860)
      e.Graphics.DrawString("_____________________", ReportFont, Brushes.Black, 275, 890)
      e.Graphics.DrawString("_____________________", ReportFont, Brushes.Black, 275, 920)
      'Service Grade'
      e.Graphics.DrawString("__________", ReportFont, Brushes.Black, 650, 920)
      e.Graphics.DrawString("*Range of 1-10.", ReportFont, Brushes.Black, 600, 950)
      e.Graphics.DrawString("10 Being highest", ReportFont, Brushes.Black, 600, 980)
      'Signature'
      e.Graphics.DrawString("____________________", ReportFont, Brushes.Black, 300, 1050)
      e.Graphics.DrawString("Signature over printed name", ReportFont, Brushes.Black, 275, 1100)

  End Sub
Posted
Updated 25-Feb-18 1:15am

When you use a PrintDocument, you gain a huge amount of flexibility and precision - you are in total control of what gets printed, when, and where. This makes reports appear exactly as you desire, but comes with a drawback: you have to print what you want, where you want it - you can't use controls to print tabulated data, and you are responsible for making sure that you print the right information on the right page: you get PrintPage event for each page in turn until you tell it there are no more pages.

This can get complicated, but this should help: How To Print a Data Grid in C# and .NET
[^]
The code is in C#, but it's well explained and there are online converters to more primitive languages: Code Converter[^]
 
Share this answer
 
v2
Please, follow this link: Printing Reports in Windows Forms[^]. There you'll find a way how to print data in tabular format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900