Dear Professor Winters,

Here is the code you wanted for printing in vb. This code contains better rems and includes right and left justified columns. You need to add a print preview dialogue control and the print doc control from the toolbox to the component tray (or dim them in the code). From the file menu on my project, I have print and print preview, on click runs the code.

Thanks for your help,

Jim Trammell

PrivateSub PrtDoc_PrintPage(ByVal sender AsObject, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrtDoc.PrintPage

Dim Address AsString

Address = lblAddress.Text & vbCrLf & _

lblCityStateZip.Text & vbCrLf & _

lblPhone.Text & vbCrLf & _

lblFax.Text

Dim sngPrintX AsSingle'Dimension the x and y coordinates as single

Dim sngPrintY AsSingle = 300

Dim fntArial12 AsNew Font("Arial", 12) 'Define the font and font size

Dim sngLineHeight AsSingle = fntArial12.GetHeight + 2 'Make line 2 pixels higher than font

Dim stzStringSize AsNew SizeF() 'SizeF structure for font size info, has a width property

Dim sngQuantityR AsSingle = 140 'set end position of a right aligned columns

Dim sngModelR AsSingle = 230

Dim sngPriceR AsSingle = 625

Dim sngLineTotalR AsSingle = 750

Dim sngDescriptionL AsSingle = 250 'set the start position of a left aligned column

'The following line layout the print form (company info, date, and labels)

e.Graphics.DrawString(lblTitle.Text, New Font("Arial", 16, FontStyle.Bold), Brushes.Black, 70, 70)

e.Graphics.DrawString(Address, New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 70, 95)

e.Graphics.DrawString(dtmDate.Text, fntArial12, Brushes.Black, 70, 250)

stzStringSize = e.Graphics.MeasureString("Quantity", fntArial12) 'measure the word quantity

sngPrintX = sngQuantityR - stzStringSize.Width 'subtract width of word from right column

'print the word quantity

e.Graphics.DrawString("Quantity", fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString("Model", fntArial12)

sngPrintX = sngModelR - stzStringSize.Width

e.Graphics.DrawString("Model", fntArial12, Brushes.Black, sngPrintX, sngPrintY)

e.Graphics.DrawString("Discription", fntArial12, Brushes.Black, sngDescriptionL, sngPrintY)

stzStringSize = e.Graphics.MeasureString("Price", fntArial12)

sngPrintX = sngPriceR - stzStringSize.Width

e.Graphics.DrawString("Price", fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString("LineTotal", fntArial12)

sngPrintX = sngLineTotalR - stzStringSize.Width

e.Graphics.DrawString("Line Total", fntArial12, Brushes.Black, sngPrintX, sngPrintY)

'The following lines layout the data in the print form

stzStringSize = e.Graphics.MeasureString(txtQuantity.Text, fntArial12)

sngPrintX = sngQuantityR - stzStringSize.Width

sngPrintY += sngLineHeight

e.Graphics.DrawString(txtQuantity.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString(txtModel.Text, fntArial12)

sngPrintX = sngModelR - stzStringSize.Width

e.Graphics.DrawString(txtModel.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

e.Graphics.DrawString(txtDescription.Text, fntArial12, Brushes.Black, sngDescriptionL, sngPrintY)

stzStringSize = e.Graphics.MeasureString(txtPrice.Text, fntArial12)

sngPrintX = sngPriceR - stzStringSize.Width

e.Graphics.DrawString(txtPrice.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString(lblSubTotal.Text, fntArial12)

sngPrintX = sngLineTotalR - stzStringSize.Width

e.Graphics.DrawString(lblSubTotal.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

'The following lines layout the tax and total

stzStringSize = e.Graphics.MeasureString(lblTaxText.Text, fntArial12)

sngPrintX = sngPriceR - stzStringSize.Width

sngPrintY += sngLineHeight * 2 'double space line

e.Graphics.DrawString(lblTaxText.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString(lblTax.Text, fntArial12)

sngPrintX = sngLineTotalR - stzStringSize.Width

e.Graphics.DrawString(lblTax.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString(lblTotalText.Text, fntArial12)

sngPrintX = sngPriceR - stzStringSize.Width

sngPrintY += sngLineHeight * 2 'double space line

e.Graphics.DrawString(lblTotalText.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

stzStringSize = e.Graphics.MeasureString(lblTotal.Text, fntArial12)

sngPrintX = sngLineTotalR - stzStringSize.Width

e.Graphics.DrawString(lblTotal.Text, fntArial12, Brushes.Black, sngPrintX, sngPrintY)

'Adds a Thank You at the bottom of the invoice

e.Graphics.DrawString("Thank You", New Font("Arial", 48, FontStyle.Bold), Brushes.Black, 225, 900)

EndSub

PrivateSub mnuFilePrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrintPreview.Click

Dim ppd AsNew PrintPreviewDialog() 'needed because PrintPreviewDialog control was not added

'Define the source for the print preview

ppd.Document = PrtDoc

ppd.ShowDialog()

EndSub

PrivateSub mnuFilePrint_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles mnuFilePrint.Click

PrtDoc.Print()

EndSub