Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > How to print all items in list box using VB 2005 express
 

How to print all items in list box using VB 2005 express

Hi
I'm trying to print my list boxes details under their sub headings of there description. I can print all the sub headings using
'Sub titles
PrintFont = New Font("Courier New", 12, FontStyle.Bold)
e.Graphics.DrawString("Model No Description Guarantee Qty Unit price", PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
PrintFont = New Font("Courier New", 12, FontStyle.Regular)
CurrentY += PrintFont.GetHeight(e.Graphics)

but now I need to get the data from the listboxes and place them under there description. Can anybody be of any help please? I have supplied my code many thanks TheCodeHunter

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
Dim invoice As Drawing.Printing.PrintDocument
invoice = New Drawing.Printing.PrintDocument()
invoice.DocumentName = "Invoice"
'wire up event for each page
AddHandler invoice.PrintPage, AddressOf Me.PrintPage

invoice.Print()
invoice.Dispose()
End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal e As Drawing.Printing.PrintPageEventArgs)

Dim PrintFont As Font
Dim CurrentY As Single

'Establish font
PrintFont = New Font("Courier New", 12)
CurrentY = e.MarginBounds.Top
'Print header
PrintFont = New Font("Courier New", 12, FontStyle.Bold)
e.Graphics.DrawString("Herne Bay Domestics Ltd", PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
PrintFont = New Font("Courier New", 10, FontStyle.Bold)
CurrentY += 2 * PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format("Monkey High Street"), PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format("Monkey land"), PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format("monkey"), PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString("Vat No: " + CStr(Format("123456")), PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
CurrentY += 2 * PrintFont.GetHeight(e.Graphics)
PrintFont = New Font("Courier New", 12, FontStyle.Bold)
'Deliver to
PrintFont = New Font("Courier New", 12, FontStyle.Bold)
e.Graphics.DrawString("Deliver To", PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
PrintFont = New Font("Courier New", 10, FontStyle.Bold)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(Titlecombobox.Text, "") + Format(Surnametextbox.Text, ""), PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(Notextbox.Text, ""), PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(Streettextbox.Text, ""), PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(Towntextbox.Text, ""), PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(PostCodetextbox.Text, ""), PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
CurrentY += 2 * PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(TelephoneNotextbox.Text, ""), PrintFont, Brushes.Black, e.MarginBounds.Right - 100, CurrentY)
CurrentY += PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString("Invoice date:", PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
CurrentY += 2 * PrintFont.GetHeight(e.Graphics)
e.Graphics.DrawString(Format(DateTimePicker2.Text), PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
CurrentY += 2 * PrintFont.GetHeight(e.Graphics)
'Sub titles
PrintFont = New Font("Courier New", 12, FontStyle.Bold)
e.Graphics.DrawString("Model No Description Guarantee Qty Unit price", PrintFont, Brushes.Black, e.MarginBounds.Left, CurrentY)
PrintFont = New Font("Courier New", 12, FontStyle.Regular)
CurrentY += PrintFont.GetHeight(e.Graphics)

'Item description

'!!! Need code to display details inlistboxes

End Sub

Private Function PaymentLine(ByVal M As Integer, ByVal PA As Single, ByVal P As Single, ByVal I As Single, ByVal B As Single) As String
Dim PL As String, S As String
Dim DL As String
PL = Space(60) 'blank out line with spaces
DL = Space(10)
'Model No
S = Format(M, "#")
Mid(PL, 5 - Len(S), Len(S)) = S
'Description
S = Format(PA, "0.00")
Mid(PL, 18 - Len(S), Len(S)) = S
'Guarantee
S = Format(P, "0.00")
Mid(PL, 32 - Len(S), Len(S)) = S
'Qty
S = Format(I, "0.00")
Mid(PL, 45 - Len(S), Len(S)) = S
'Unit price
S = Format(B, "0.00")
Mid(PL, 57 - Len(S), Len(S)) = S
Return (PL)
Return (DL)
End Function
TheCodeHunter  Friday, November 27, 2009 11:15 AM
Since you a columnar layout, if you convert to a ListView instead of a ListBox, you'll have a better display and the printing code will be much easier.
JohnWein  Friday, November 27, 2009 2:42 PM

You can use google to search for other answers

Custom Search

More Threads

• call a sqlserver function from vb2005
• First 3 characters
• Warning With Large Revision Numbers
• how to get value from datagrid?
• 2 dimentional array's
• How do you kill your application?
• replacing a file extention with another
• dragdrop??
• Delete in gridview
• Need help with OOP for Bank Account program