Problems with Pagesettings (PrintDocument)

fpineda101

Well-known member
Joined
Nov 14, 2005
Messages
122
Location
Los Angeles, CA
Programming Experience
1-3
Here is my code...

VB.NET:
private bmp as bitmap
 
Private Sub GridDetail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridDetail.Click
bmp = getsnap(GridDetail)
'PrintDocument1.Print()
PrintPreviewDialog1.ShowDialog()
End Sub
 
Private Function getsnap(ByVal ctrl As DataGridView) As Bitmap
Dim abmp As New Bitmap(ctrl.Width, ctrl.Height)
Dim g As Graphics = Graphics.FromImage(abmp)
Dim srcPoint As Point = Me.Location
If Not ctrl.Parent Is Nothing Then
srcPoint = ctrl.Parent.PointToScreen(ctrl.Location)
End If
g.CopyFromScreen(srcPoint, New Point(0, 0), ctrl.Size)
g.Dispose()
Return abmp
End Function
 
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
e.PageSettings.Color = False
e.PageSettings.Margins.Top = 10
e.PageSettings.Margins.Bottom = 10
e.PageSettings.Margins.Left = 10
e.PageSettings.Margins.Right = 10
e.PageSettings.Landscape = True
e.Graphics.DrawImage(bmp, e.MarginBounds.Location)
e.HasMorePages = False
End Sub
My printpreview didn't go into landscape or take any of the margins I specified. Can someone point me in the right direction?
 
Last edited by a moderator:
I would say set this for the PrintDocuments DefaultPageSettings before calling print/preview.
 
Back
Top