what_5626 0 Newbie Poster

i was trying to print the content in the listbox but instead of printing, i come out with the saving button as document in m.word. how to print my content in list box when i click on my print button straight away.. this is my coding..

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
PrintDocument1.PrinterSettings.Copies = 1
PrintDocument1.Print()
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim x As Integer = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim lineheight As Single = Me.ListBox1.Font.GetHeight(e.Graphics)
For Each item As String In Me.ListBox1.Items
e.Graphics.DrawString(item, Me.ListBox1.Font, Brushes.Black, x, y)
y += lineheight
Next
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.