0

Actually i am working on a school management project in which i want to print result of student. Now the problem is that the preview of winform in which the controls are there is coming in portrait mode and not in landscape mode.

This is my code i used to print:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    'Add a Panel control.
    Dim panel As New Panel()
    Me.Controls.Add(panel)

    'Create a Bitmap of size same as that of the Form.
    Dim grp As Graphics = panel.CreateGraphics()
    Dim formSize As Size = Me.ClientSize
    Bitmap = New Bitmap(formSize.Width, formSize.Height, grp)
    grp = Graphics.FromImage(Bitmap)

    'Copy screen area that that the Panel covers.
    Dim panelLocation As Point = PointToScreen(panel.Location)
    grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize)


    'PrintPreviewDialog1.ShowDialog()

    PrintPreviewDialog1.Document = PrintDocument1
    PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
    PrintPreviewDialog1.ShowDialog()

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    e.Graphics.DrawImage(bitmap, 0, 0)
End Sub

i am attaching a picture of what above code does. Portrait Result

I want that it should be previewed and get print in landscape mode instead of portrait.

do i need to change anything in bitmap property? any help would be appreciated

Thanks.

  • Look at the related column on the right, _printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;_ – Steve Nov 20 '16 at 08:43
  • can you please tell me were to exactly put this code.? i mean in printDocument? or in printPreview? – Anonymous MK Nov 20 '16 at 08:56

0 Answers0