Results 1 to 6 of 6

Thread: Help I can't adjust Picture in PrintDocument

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    3

    Question Help I can't adjust Picture in PrintDocument

    Hey guys just a newbie, please the picture below
    Name:  Box.jpg
Views: 165
Size:  13.6 KB
    This is the layout when clicking print and print preview, and here is the code
    Name:  code.jpg
Views: 164
Size:  38.8 KB
    I cant resize the picture, the picture in the form is fix I can't make it a whole A4

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

    Re: Help I can't adjust Picture in PrintDocument

    Try setting Left, Top, Width, Height...

    Code:
    e.graphics.drawimage(db, l, t, w, h)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,058

    Re: Help I can't adjust Picture in PrintDocument

    Code:
    PrintPreviewDialog1.ToString() ???
    That does nothing.

    Try changing that line to...

    Code:
    PrintPreviewDialog1.WindowState = FormWindowState.Maximized

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    3

    Re: Help I can't adjust Picture in PrintDocument

    I will try it thank you, i just put it because when i click print preview twice there is an error on the code and when after i put the .tostring the error is gone and i can check the print preview several times

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    3

    Re: Help I can't adjust Picture in PrintDocument

    This what happen when put length and top
    Attachment 186382

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,058

    Re: Help I can't adjust Picture in PrintDocument

    Try this...

    Code:
    Imports System.Drawing.Printing
    
    Public Class Form1
    
        Private WithEvents PrintDocument1 As New PrintDocument
        Private ppd As New PrintPreviewDialog With {.Document = PrintDocument1, .windowstate = FormWindowState.Maximized}
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ppd.ShowDialog()
        End Sub
    
        Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim img As New Bitmap("a bitmap")
    
            Dim l As Integer
            Dim t As Integer
            Dim w As Integer = img.Width
            Dim h As Integer = img.Height
    
            If w > e.PageBounds.Width Then
                w = e.PageBounds.Width
                h = CInt(w / img.Width * img.Height)
            End If
    
            If h > e.PageBounds.Height Then
                h = e.PageBounds.Height
                w = CInt(h / img.Height * img.Width)
            End If
    
            l = CInt(e.PageBounds.Left + ((e.PageBounds.Width - w) / 2))
            t = CInt(e.PageBounds.Top + ((e.PageBounds.Height - h) / 2))
    
            e.Graphics.DrawImage(img, l, t, w, h)
        End Sub
    
    End Class

Posting Permissions

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



Click Here to Expand Forum to Full Width