dcsimg
Results 1 to 2 of 2

Thread: Help with e.Graphics.Drawing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2015
    Posts
    110

    Help with e.Graphics.Drawing

    So there very well could be an easier and better way to do this, but this is what I have so far. What I'm trying to accomplish is print out the text in various labels, textboxes, and comboboxes onto a printed piece of paper. That piece of paper is a form that I'm trying to fill out. It will have things like name, address, city, and state. I am currently using a PrintDocument to achieve this and it works. My question is is there a way to measure on my piece of paper and tell my code to print there? So let's say I want my text from cboDealer to print 4 inches from the left edge of the paper and 3 inches from the top. Can I convert this somehow?

    My code so far. First for the PrintDocument:

    Code:
       Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
    
            e.Graphics.DrawString(lblVIN.Text, lblVIN.Font, Brushes.Black, 100, 100)
            e.Graphics.DrawString(cboModelYear.Text, cboModelYear.Font, Brushes.Black, 150, 100)
            e.Graphics.DrawString(cboDealer.Text, cboModelYear.Font, Brushes.Black, New Point(500, 500))
    
        End Sub
    And then for the button I have to actually print the page through the printer.

    Code:
       Private Sub cmdPrint_Click(sender As Object, e As EventArgs) Handles cmdPrint.Click
    
    
            PrintDialog1.Document = PrintDocument1
            PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
            PrintDialog1.AllowSomePages = True
    
            If PrintDialog1.ShowDialog = DialogResult.OK Then
                PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
                PrintDocument1.Print()
                ' PrintPreviewDialog1.Document = PrintPreviewDialog1.Document
                ' PrintPreviewDialog1.ShowDialog()
            End If
    
        End Sub
    Thanks for any help.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,924

    Re: Help with e.Graphics.Drawing

    Code:
    e.Graphics.DrawString(cboDealer.Text, cboModelYear.Font, Brushes.Black, New Point(4 * e.Graphics.dpiX, 3 * e.Graphics.dpiY))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width