تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] أرجوكم مساعدة طباعة الفورم
#1
Sad 
السلام عليكم ورحمة الله وبركاته بداية أقول للقائمين على هذا الموقع جزاكم الله كل خير ورفعكم الله درجات بعلمكم أما بعد أخوتي أريد طريقة لتحديد الطابعة في البرينت فورم أريد لكل أداة برينت فورم أن أحدد لها طابعة أي لا أريد أن يتم الطباعة فقط على الطابعة الافتراضية كان هذا سؤالي وأرجوكم أريد حل وشكراً لكم سلفاً.
الرد }}}
تم الشكر بواسطة: مبرمج بلا حدود
#2
سلام

كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Using prntr As New PrintDialog
        If prntr.ShowDialog = vbOK Then
            PrintForm1.PrinterSettings = prntr.PrinterSettings
            PrintForm1.Print()
        End If
    End Using
End Sub

موفقين
متغيب
الرد }}}
تم الشكر بواسطة: FIRAS SHAMMA , مبرمج بلا حدود
#3
شكراً جزيلاً لك أخي لكن كيف أضع هذه الطابعة كطابعة افتراضية للبرينت فورم وشكراً لك أخي
الرد }}}
تم الشكر بواسطة: مبرمج بلا حدود
#4
سلام

ممكن تحدد لها اسم الطابعه مياشره
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    PrintForm1.PrinterSettings.PrinterName = "اسم الطابعه"
    PrintForm1.Print()
End Sub

موفقين
متغيب
الرد }}}
تم الشكر بواسطة: مبرمج بلا حدود , FIRAS SHAMMA
#5
السلام عليكم ورحمة الله وبركاته
لدي استفسار بخصوص الطباعة ان امكن وسمحتم لي
1- كيفية طباعة محتويات فورم على حجم A4 بشكل طولي يعني (21*29.7) او عرضي يعني (29.7*21)
2- كيفية عمل معاينة قبل الطباعة
3- كيفية حفظ المحتويات قبل الطباعة كصورة

هذا وجزاكم الله خير وباركـ الله فيكم
وجعله الله في موازين حسناتكم
الرد }}}
تم الشكر بواسطة: FIRAS SHAMMA
#6
سلام

أخي مبرمج بلا حدود الاداه printform ما عرفتلها
لكن لقيتلك كلاس وعدلت متغير الصوره من private الى public عشان تقدر تقرا الصوره وتحفظها
http://stackoverflow.com/questions/97765...rm-autofit
كود :
Imports System.Drawing
Imports System.Windows.Forms
''' <summary>
''' Prints a screengrab of the form
''' </summary>
''' <remarks></remarks>
Public Class PrintForm
    'USAGE:
    ' Dim pf As New PrintForm(Me)
    ' pf.PrintPreview()
    ' - or-
    ' pf.Print()
    '
    Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal hDIDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean ' API call to help generate final screenshot
    Public mbmpScreenshot As Bitmap ' Variable to store screenshot
    Private mblnLandscape As Boolean = False
    Public Enum PrintMode_ENUM As Integer
        [Default]
        FitToPage
    End Enum
    Private menuPrintMode As PrintMode_ENUM = PrintMode_ENUM.Default
    '
    Private mfrm As Form
    Public Sub New(ByVal frm As Form)
        mfrm = frm
        Call GrabScreen()
    End Sub
    '
    ''' <summary>
    ''' Determines page settings for current page e.g. Orientation
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub QueryPageSettings(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs)
        '
        Dim pgsTemp As System.Drawing.Printing.PageSettings = New System.Drawing.Printing.PageSettings()
        pgsTemp.Landscape = mblnLandscape
        e.PageSettings = pgsTemp
        '
    End Sub
    '
    Public Sub Print(ByVal landscape As Boolean, ByVal printMode As PrintMode_ENUM, Optional ByVal docname As String = "PrintForm", Optional ByVal PrinterName As String = "")
        mblnLandscape = landscape
        menuPrintMode = printMode
        'create the document object
        Using pdcNew As New Printing.PrintDocument
            '
            'wire up event handlers to handle pagination
            AddHandler pdcNew.PrintPage, AddressOf PrintPage
            AddHandler pdcNew.QueryPageSettings, AddressOf QueryPageSettings
            '
            Using docOutput As Printing.PrintDocument = pdcNew
                If PrinterName > "" Then
                    docOutput.PrinterSettings.PrinterName = PrinterName
                End If
                docOutput.DocumentName = docname
                docOutput.Print()
            End Using
        End Using
    End Sub
    '
    ''' <summary>
    ''' Preview the Report on screen
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub PrintPreview(ByVal landscape As Boolean, ByVal printMode As PrintMode_ENUM, Optional ByVal docname As String = "PrintForm", Optional ByVal Owner As Form = Nothing)
        mblnLandscape = landscape
        menuPrintMode = printMode
        '
        'create the document object
        Using pdcNew As New Printing.PrintDocument
            '
            'wire up event handlers to handle pagination
            AddHandler pdcNew.PrintPage, AddressOf PrintPage
            AddHandler pdcNew.QueryPageSettings, AddressOf QueryPageSettings
            '
            Using ppvPreview As New PrintPreviewDialog
                ppvPreview.Document = pdcNew
                ppvPreview.FindForm.WindowState = FormWindowState.Maximized
                If IsNothing(Owner) Then
                    ppvPreview.ShowDialog()
                Else
                    ppvPreview.ShowDialog(Owner)
                End If
            End Using
        End Using
    End Sub
    Sub PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim g As Graphics = e.Graphics 'shortcut
        'g.DrawRectangle(Pens.Red, e.MarginBounds) 'DEBUG: use this line to check margins        
        '
        ' Method that handles the printing
        Using objImageToPrint As Graphics = e.Graphics
            Select Case menuPrintMode
                Case PrintMode_ENUM.FitToPage
                    Dim rctTarget As Rectangle
                    If (mbmpScreenshot.Width / mbmpScreenshot.Height) < (e.MarginBounds.Width / e.MarginBounds.Height) Then
                        'fit height
                        rctTarget = New Rectangle(e.MarginBounds.X, e.MarginBounds.Y, CInt(mbmpScreenshot.Width * e.MarginBounds.Height / mbmpScreenshot.Height), e.MarginBounds.Height)
                    Else
                        'fit width
                        rctTarget = New Rectangle(e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, CInt(mbmpScreenshot.Height * e.MarginBounds.Width / mbmpScreenshot.Width))
                    End If
                    'g.DrawRectangle(Pens.Blue, rctTarget) 'DEBUG: use this line to check target rectangle
                    objImageToPrint.DrawImage(mbmpScreenshot, rctTarget)
                Case Else 'default
                    objImageToPrint.DrawImage(mbmpScreenshot, 0, 0)
            End Select
        End Using
        '
        e.HasMorePages = False
    End Sub
    '
    Private Sub GrabScreen()
        ' Performs a screenshot, saving results to bmpScreenshot
        Dim objGraphics As Graphics = mfrm.CreateGraphics
        Dim rctForm As Rectangle = mfrm.ClientRectangle 'including the border is beyond the scope of this demo program. See http://support.microsoft.com/kb/84066 for GetSystemMetrics() API to get  size of border
        '
        Const SRCCOPY As Integer = &HCC0020
        mbmpScreenshot = New Bitmap(rctForm.Width, rctForm.Height, objGraphics)
        Dim objGraphics2 As Graphics = Graphics.FromImage(mbmpScreenshot)
        Dim deviceContext1 As IntPtr = objGraphics.GetHdc
        Dim deviceContext2 As IntPtr = objGraphics2.GetHdc
        '
        BitBlt(deviceContext2, rctForm.X, rctForm.Y, rctForm.Width, rctForm.Height, deviceContext1, 0, 0, SRCCOPY)
        objGraphics.ReleaseHdc(deviceContext1)
        objGraphics2.ReleaseHdc(deviceContext2)
    End Sub
    '
End Class

كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim p As New PrintForm(Me)

    'p.PrintPreview(False, PrintForm.PrintMode_ENUM.FitToPage)

    PictureBox1.Image = p.mbmpScreenshot

End Sub


موفقين
متغيب
الرد }}}
تم الشكر بواسطة: مبرمج بلا حدود , FIRAS SHAMMA
#7
(06-08-15, 12:38 AM)الطالب كتب : سلام

أخي مبرمج بلا حدود الاداه printform ما عرفتلها
لكن لقيتلك كلاس وعدلت متغير الصوره من private الى public عشان تقدر تقرا الصوره وتحفظها
http://stackoverflow.com/questions/97765...rm-autofit
كود :
Imports System.Drawing
Imports System.Windows.Forms
''' <summary>
''' Prints a screengrab of the form
''' </summary>
''' <remarks></remarks>
Public Class PrintForm
   'USAGE:
   ' Dim pf As New PrintForm(Me)
   ' pf.PrintPreview()
   ' - or-
   ' pf.Print()
   '
   Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal hDIDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean ' API call to help generate final screenshot
   Public mbmpScreenshot As Bitmap ' Variable to store screenshot
   Private mblnLandscape As Boolean = False
   Public Enum PrintMode_ENUM As Integer
       [Default]
       FitToPage
   End Enum
   Private menuPrintMode As PrintMode_ENUM = PrintMode_ENUM.Default
   '
   Private mfrm As Form
   Public Sub New(ByVal frm As Form)
       mfrm = frm
       Call GrabScreen()
   End Sub
   '
   ''' <summary>
   ''' Determines page settings for current page e.g. Orientation
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub QueryPageSettings(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs)
       '
       Dim pgsTemp As System.Drawing.Printing.PageSettings = New System.Drawing.Printing.PageSettings()
       pgsTemp.Landscape = mblnLandscape
       e.PageSettings = pgsTemp
       '
   End Sub
   '
   Public Sub Print(ByVal landscape As Boolean, ByVal printMode As PrintMode_ENUM, Optional ByVal docname As String = "PrintForm", Optional ByVal PrinterName As String = "")
       mblnLandscape = landscape
       menuPrintMode = printMode
       'create the document object
       Using pdcNew As New Printing.PrintDocument
           '
           'wire up event handlers to handle pagination
           AddHandler pdcNew.PrintPage, AddressOf PrintPage
           AddHandler pdcNew.QueryPageSettings, AddressOf QueryPageSettings
           '
           Using docOutput As Printing.PrintDocument = pdcNew
               If PrinterName > "" Then
                   docOutput.PrinterSettings.PrinterName = PrinterName
               End If
               docOutput.DocumentName = docname
               docOutput.Print()
           End Using
       End Using
   End Sub
   '
   ''' <summary>
   ''' Preview the Report on screen
   ''' </summary>
   ''' <remarks></remarks>
   Public Sub PrintPreview(ByVal landscape As Boolean, ByVal printMode As PrintMode_ENUM, Optional ByVal docname As String = "PrintForm", Optional ByVal Owner As Form = Nothing)
       mblnLandscape = landscape
       menuPrintMode = printMode
       '
       'create the document object
       Using pdcNew As New Printing.PrintDocument
           '
           'wire up event handlers to handle pagination
           AddHandler pdcNew.PrintPage, AddressOf PrintPage
           AddHandler pdcNew.QueryPageSettings, AddressOf QueryPageSettings
           '
           Using ppvPreview As New PrintPreviewDialog
               ppvPreview.Document = pdcNew
               ppvPreview.FindForm.WindowState = FormWindowState.Maximized
               If IsNothing(Owner) Then
                   ppvPreview.ShowDialog()
               Else
                   ppvPreview.ShowDialog(Owner)
               End If
           End Using
       End Using
   End Sub
   Sub PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
       Dim g As Graphics = e.Graphics 'shortcut
       'g.DrawRectangle(Pens.Red, e.MarginBounds) 'DEBUG: use this line to check margins        
       '
       ' Method that handles the printing
       Using objImageToPrint As Graphics = e.Graphics
           Select Case menuPrintMode
               Case PrintMode_ENUM.FitToPage
                   Dim rctTarget As Rectangle
                   If (mbmpScreenshot.Width / mbmpScreenshot.Height) < (e.MarginBounds.Width / e.MarginBounds.Height) Then
                       'fit height
                       rctTarget = New Rectangle(e.MarginBounds.X, e.MarginBounds.Y, CInt(mbmpScreenshot.Width * e.MarginBounds.Height / mbmpScreenshot.Height), e.MarginBounds.Height)
                   Else
                       'fit width
                       rctTarget = New Rectangle(e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, CInt(mbmpScreenshot.Height * e.MarginBounds.Width / mbmpScreenshot.Width))
                   End If
                   'g.DrawRectangle(Pens.Blue, rctTarget) 'DEBUG: use this line to check target rectangle
                   objImageToPrint.DrawImage(mbmpScreenshot, rctTarget)
               Case Else 'default
                   objImageToPrint.DrawImage(mbmpScreenshot, 0, 0)
           End Select
       End Using
       '
       e.HasMorePages = False
   End Sub
   '
   Private Sub GrabScreen()
       ' Performs a screenshot, saving results to bmpScreenshot
       Dim objGraphics As Graphics = mfrm.CreateGraphics
       Dim rctForm As Rectangle = mfrm.ClientRectangle 'including the border is beyond the scope of this demo program. See http://support.microsoft.com/kb/84066 for GetSystemMetrics() API to get  size of border
       '
       Const SRCCOPY As Integer = &HCC0020
       mbmpScreenshot = New Bitmap(rctForm.Width, rctForm.Height, objGraphics)
       Dim objGraphics2 As Graphics = Graphics.FromImage(mbmpScreenshot)
       Dim deviceContext1 As IntPtr = objGraphics.GetHdc
       Dim deviceContext2 As IntPtr = objGraphics2.GetHdc
       '
       BitBlt(deviceContext2, rctForm.X, rctForm.Y, rctForm.Width, rctForm.Height, deviceContext1, 0, 0, SRCCOPY)
       objGraphics.ReleaseHdc(deviceContext1)
       objGraphics2.ReleaseHdc(deviceContext2)
   End Sub
   '
End Class

كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim p As New PrintForm(Me)

   'p.PrintPreview(False, PrintForm.PrintMode_ENUM.FitToPage)

   PictureBox1.Image = p.mbmpScreenshot

End Sub


موفقين

وعليكم السلام ورحمة الله وبركاته 
باركـ الله فيككـ اخي وجزاكـ الله خير وجعله الله في موازين حسناتكـ 
جاري التجربة وعائد لكـ غداً ان شاءالله 
وفقكـ الله
الرد }}}
تم الشكر بواسطة: FIRAS SHAMMA
#8
السلام عليكم ورحمة الله وبركاته
جزاكـ الله خير اخي وباركـ الله فيكـ
الحمدلله يعمل الكود لدي لكن لدي استفسار كيف اجعل الفورم على حجم A4
حاولت اغير بإبعاد الفورم لكن الظاهر انه لايعتمد على ال cm
واستفسار اخر هل من كود لحفظ الصورة على الحاسبة جزاك الله خير اقصد الصورة التي ناخذها للفورم
جزاكـ الله خير وباركـ الله فيكـ وجعله الله في موازين حسناتكـ
ربي يحفظكـ
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] مساعدة في تقرير mrfenix93 1 41 24-03-24, 10:29 PM
آخر رد: mrfenix93
  مساعدة jalaltech 1 95 07-03-24, 07:38 PM
آخر رد: قناص المدينة
  [VB.NET] مساعدة فى كود فاتورة اللكترونية asdfar1977 2 194 02-03-24, 02:00 AM
آخر رد: asdfar1977
  مساعدة فى كود فاتورة الكترونية asdfar1977 0 80 29-02-24, 07:14 PM
آخر رد: asdfar1977
Photo [VB.NET] مشكلة في شكل الفورم abuyazan 5 293 27-02-24, 09:38 PM
آخر رد: aljzazy
  [C#.NET] طباعة بيانات داتا جرد فيو h2551996 0 84 25-02-24, 02:31 PM
آخر رد: h2551996
  مساعدة jalaltech 0 133 17-02-24, 02:15 AM
آخر رد: jalaltech
  طلب مساعدة AHMED213 3 323 06-02-24, 09:39 PM
آخر رد: AHMED213
  [VB.NET] طلب مساعدة AHMED213 0 221 31-01-24, 12:56 AM
آخر رد: AHMED213
  [VB.NET] مشكلة ظهور textbox بعد حذفه من الفورم مبرمج صغير 1 1 221 27-01-24, 02:04 AM
آخر رد: مبرمج صغير 1

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم