Hi How can i print listview with database im using phpmyadmin xampp
-
im making insert update and delete with database for my activity and the teacher give task to add print and im trying to make on my own but its diffucult for me i hope you can help me out with these. im beginner at visual basic. im using printdocument and printpreviewdialog Here my code Print button
Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click
Dim PrintPreview As New PrintPreviewDialog
PrintPreview.Document = PrintDocument1
PrintPreview.ShowDialog()
End SubPrint Document Print Page
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim H As Integer = 0
H = 50
e.Graphics.DrawString("PRINT", New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
e.Graphics.DrawString(Itm.SubItems(0).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(1).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(2).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(3).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(4).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(5).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(6).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(7).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(8).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(9).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
H += 20
Next
End Subhere's my ouput Output
-
im making insert update and delete with database for my activity and the teacher give task to add print and im trying to make on my own but its diffucult for me i hope you can help me out with these. im beginner at visual basic. im using printdocument and printpreviewdialog Here my code Print button
Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click
Dim PrintPreview As New PrintPreviewDialog
PrintPreview.Document = PrintDocument1
PrintPreview.ShowDialog()
End SubPrint Document Print Page
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim H As Integer = 0
H = 50
e.Graphics.DrawString("PRINT", New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
e.Graphics.DrawString(Itm.SubItems(0).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(1).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(2).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(3).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(4).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(5).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(6).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(7).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(8).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(9).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
H += 20
Next
End Subhere's my ouput Output
You are drawing every sub-item starting at the same horizontal coordinate. Unsurprisingly, this results in the text of every sub-item overlapping. You need to increase the horizontal coordinate for each sub-item. You can either use the
MeasureString
method[^] to measure how much space your string will take up, or used fixed coordinates and use theDrawString
overload[^] which limits the size of the output to prevent the text from overlapping.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
im making insert update and delete with database for my activity and the teacher give task to add print and im trying to make on my own but its diffucult for me i hope you can help me out with these. im beginner at visual basic. im using printdocument and printpreviewdialog Here my code Print button
Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click
Dim PrintPreview As New PrintPreviewDialog
PrintPreview.Document = PrintDocument1
PrintPreview.ShowDialog()
End SubPrint Document Print Page
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim H As Integer = 0
H = 50
e.Graphics.DrawString("PRINT", New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
e.Graphics.DrawString(Itm.SubItems(0).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(1).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(2).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(3).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(4).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(5).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(6).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(7).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(8).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(9).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
H += 20
Next
End Subhere's my ouput Output
You are drawing all 10 subitems at the same location on the page. You need to change the X location for each item. The code could be simplified by creating a loop and using a single Font element:
Dim TnrFont as Drawing.Font = New Drawing.Font("Times New Roman", 10) e.Graphics.DrawString("PRINT", TnrFont, Brushes.Black, 50, H) For Each Itm As ListViewItem In ListView1.Items e.Graphics.DrawString(Itm.Text, TnrFont, Brushes.Black, 50, H) Dim Left as Integer = 150 For subindex as Integer = 0 To 9 e.Graphics.DrawString(Itm.SubItems(subindex).Text, TnrFont, Brushes.Black, Left, H) ' Add the offset of the field size to "Left" Left += 100 ' or whatever value to move it to the right on the page Next H += 20 Next