Question

I have run into another problem with my current project. I have a form that I need to print. Doing some searching online I found a few examples and implemented it into my code. It prints but prints all my text boxes and labels stacked on top of one another. How can I get this to print my textboxes and labels formatted as I have them in the form?

Here is my code:

 Private Sub PrintToolStripMenuItem1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem1.Click

        PrintDocument1.PrinterSettings.Copies = 2
        PrintDocument1.Print()

    End Sub

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

        e.Graphics.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label1.Text, Label1.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label2.Text, Label2.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(datebox.Text, datebox.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label3.Text, Label3.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(locationbox.Text, locationbox.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label4.Text, Label4.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(groupbox.Text, groupbox.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label5.Text, Label5.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(passbox.Text, passbox.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label7.Text, Label7.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(TextBox6.Text, TextBox6.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(apbox.Text, apbox.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(Label8.Text, Label8.Font, Brushes.Blue, 100, 100)
        e.Graphics.DrawString(TextBox7.Text, TextBox7.Font, Brushes.Blue, 100, 100)

    End Sub

Im still new to vb 2010 so any help is appreciated, Thanks!

Was it helpful?

Solution

Just realized my mistake. I'm as blind as a bat, as it was in my face the entire time.

Just in case anyone else ever needs to figure this out.

e.Graphics.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Blue, X-coordinate, Y-coordinate)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top