المشاركات : 669
المواضيع 88
الإنتساب : Aug 2016
السمعة :
97
الشكر: 798
تم شكره 1154 مرات في 488 مشاركات
14-09-17, 05:05 AM
(آخر تعديل لهذه المشاركة : 14-09-17, 05:06 AM {2} بواسطة Rabeea Qbaha.)
مرحبا شباب،
شغال على كود يطبع الفورم، يقوم باخذ القورم و عرضه في PrintPreviewDialog.
لكن عندما يظهر PrintPreviewDialog يكون بالحجم المصغر Normal و انا اريده ان يكون ملئ الشاشه عندا فتحه maximized.
هذا الكود :
كود :
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.PrinterSettings.DefaultPageSettings.Margins = New Printing.Margins(0, 0, 0, 0)
PrintForm1.Print()
بحثت في الانترنت فوجدت هذا الكود لعمل المطلوب :
كود :
DirectCast(PrintPreviewDialog1, Form).WindowState = FormWindowState.Maximized
لكن انا لا استخدم PrintPreviewDialog1 بل استدعيه مباشره.
مساعدتكم شباب.
المشاركات : 169
المواضيع 0
الإنتساب : Jul 2017
السمعة :
32
الشكر: 585
تم شكره 232 مرات في 130 مشاركات
14-09-17, 11:34 AM
(آخر تعديل لهذه المشاركة : 14-09-17, 11:35 AM {2} بواسطة أبو نوره.)
مرحبا اخى
افضل تستخدم PrintDocument1
PHP كود :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PrintDocument1.PrinterSettings.DefaultPageSettings.Margins = New Printing.Margins(0, 0, 0, 0) Me.PrintPreviewDialog1.Document = Me.PrintDocument1 Me.PrintPreviewDialog1.WindowState = FormWindowState.Maximized Me.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(GetFormImage, New Point(0, 0))
End Sub
Private Function GetFormImage(Optional ByVal include_borders As Boolean = False) As Bitmap ' Make the bitmap. Dim wid As Integer = Me.Width Dim hgt As Integer = Me.Height Dim bm As New Bitmap(wid, hgt)
' Draw the form onto the bitmap. Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
' If we want the borders, return the bitmap. If include_borders Then Return bm
' Make a smaller bitmap without borders. wid = Me.ClientSize.Width hgt = Me.ClientSize.Height Dim bm2 As New Bitmap(wid, hgt)
' Get the offset from the window's corner to its client ' area's corner. Dim pt As New Point(0, 0) pt = PointToScreen(pt) Dim dx As Integer = pt.X - Me.Left Dim dy As Integer = pt.Y - Me.Top
' Copy the part of the original bitmap that we want ' into the bitmap. Dim gr As Graphics = Graphics.FromImage(bm2) gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt), GraphicsUnit.Pixel) Return bm2 End Function
End Class
المشاركات : 669
المواضيع 88
الإنتساب : Aug 2016
السمعة :
97
الشكر: 798
تم شكره 1154 مرات في 488 مشاركات
14-09-17, 07:43 PM
(آخر تعديل لهذه المشاركة : 14-09-17, 07:45 PM {2} بواسطة Rabeea Qbaha.)
(14-09-17, 11:34 AM)أبو نوره كتب : مرحبا اخى
افضل تستخدم PrintDocument1
PHP كود :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PrintDocument1.PrinterSettings.DefaultPageSettings.Margins = New Printing.Margins(0, 0, 0, 0) Me.PrintPreviewDialog1.Document = Me.PrintDocument1 Me.PrintPreviewDialog1.WindowState = FormWindowState.Maximized Me.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(GetFormImage, New Point(0, 0))
End Sub
Private Function GetFormImage(Optional ByVal include_borders As Boolean = False) As Bitmap ' Make the bitmap. Dim wid As Integer = Me.Width Dim hgt As Integer = Me.Height Dim bm As New Bitmap(wid, hgt)
' Draw the form onto the bitmap. Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
' If we want the borders, return the bitmap. If include_borders Then Return bm
' Make a smaller bitmap without borders. wid = Me.ClientSize.Width hgt = Me.ClientSize.Height Dim bm2 As New Bitmap(wid, hgt)
' Get the offset from the window's corner to its client ' area's corner. Dim pt As New Point(0, 0) pt = PointToScreen(pt) Dim dx As Integer = pt.X - Me.Left Dim dy As Integer = pt.Y - Me.Top
' Copy the part of the original bitmap that we want ' into the bitmap. Dim gr As Graphics = Graphics.FromImage(bm2) gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt), GraphicsUnit.Pixel) Return bm2 End Function
End Class
شكرا كثيرا ابو نوره
لكن يوجد مشكله صغيره ، وهي انه لا يتم اظهار محتوى الفورم للطباعه.
يعني عندي عدد من ال textbox يوجد فيها بيانات، هذه ال textbox لا تظهر.
|