dcsimg
Results 1 to 1 of 1

Thread: [RESOLVED] How to fit chart to page when printing using PrintDocument

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    428

    Resolved [RESOLVED] How to fit chart to page when printing using PrintDocument

    Hi,
    I am trying to figure out how to fit a chat to a landscape oriented page but can't make it to work:

    Code:
        Private Sub Print1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles Print1.PrintPage
    
            Dim newMargins As Printing.Margins
            newMargins = New Printing.Margins(0, 0, 0, 0)
            Print1.DefaultPageSettings.Margins = newMargins
            Chart1.Printing.PrintPaint(e.Graphics, New Rectangle(0, 0, Chart1.Width, Chart1.Height)) ' draws the chart for me; I think here it goes wrong
    
    
        End Sub
    
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
    
            Print1.DefaultPageSettings.Landscape = True
            Chart1.Printing.PrintDocument = Print1
            Chart1.Printing.Print(True)
    
        End Sub
    
        Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
    
            Print1.DefaultPageSettings.Landscape = True
            Chart1.Printing.PrintDocument = Print1
            Chart1.Printing.PrintPreview()
    
        End Sub
    The pictureboxes are for print and preview before printing.

    What is it that I am not doing or doing wrong?
    Thanks in advance for your help.

    Edit:
    Found out. The issue was me

    Code:
       Private Sub Print1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles Print1.PrintPage
    
            Dim chartPosition As Rectangle = New Rectangle(e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height)
            Chart1.Printing.PrintPaint(e.Graphics, chartPosition)
    
        End Sub
    Last edited by Grand; Mar 26th, 2020 at 01:22 PM.

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