نمایش نتایج 1 تا 9 از 9

نام تاپیک: print مستقیم form

  1. #1

    Question print مستقیم form

    سلام
    می خواستم ببینم راهی هست که بدون باز شدن print preview و پنجره های دیگر فرم برنامه رو پرینت کرد

  2. #2
    کاربر دائمی آواتار ali_kolahdoozan
    تاریخ عضویت
    بهمن 1384
    محل زندگی
    اون سر دنیا
    پست
    1,631
    خوب priview نگیرید مستقیم printdocumnet رو چاپ کنید

  3. #3
    ممنون میشم اگه یه مثال ساده برام بزنید

  4. #4
    Private Declare Function PrintWindow Lib "user32.dll" (ByVal _
    hwnd As IntPtr, ByVal hdcBlt As IntPtr, ByVal nFlags As _
    UInt32) As Boolean
    Dim screenGrab As Bitmap

    Private Sub CaptureScreen()
    'captures Form1 into screenGrab
    screenGrab = New Bitmap(GroupBox1.Width, GroupBox1.Height)
    Dim g As Graphics = Graphics.FromImage(screenGrab)
    Dim hdc As IntPtr = g.GetHdc
    test.PrintWindow(GroupBox1.Handle, hdc, Nothing)

    g.ReleaseHdc(hdc)
    g.Flush()
    g.Dispose()

    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
    ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    ' page bounds are in 100ths of an inch...
    Dim pagewidth As Single = e.PageBounds.Width / 100
    Dim pageheight As Single = e.PageBounds.Height / 100
    ' how many pixels in the print area?
    Dim pagewidthpixels As Integer = pagewidth * e.PageSettings.PrinterResolution.X
    Dim pageheightpixels As Integer = pageheight * e.PageSettings.PrinterResolution.Y
    ' how many times does the screengrab image fit into the print area?
    Dim width_ratio As Double = pagewidthpixels / screenGrab.Width
    Dim height_ratio As Double = pageheightpixels / screenGrab.Height
    ' If the screengrab fits x times, then reduce the resolution of the printer by x.
    ' Only use one scaling_factor to keep it in proportion
    ' use the smaller of the two to keep it on the page
    Dim scaling_factor As Double
    If width_ratio > height_ratio Then
    scaling_factor = height_ratio
    Else
    scaling_factor = width_ratio
    End If
    ' set the resolution of the image - this will scale it to fit on the printed page
    screenGrab.SetResolution(e.PageSettings.PrinterRes olution.X / scaling_factor, e.PageSettings.PrinterResolution.Y / scaling_factor)
    ' send it to the printer
    e.Graphics.DrawImage(screenGrab, 0, 0)

    End Sub

  5. #5
    کد زیر را مطالعه کنید . اگر متوجه نشدید source را برایتان ایمیل می کنم متاسفانه نتوانستم در این قسمت source را upload کنم
    Private Declare Function PrintWindow Lib "user32.dll" (ByVal _
    hwnd As IntPtr, ByVal hdcBlt As IntPtr, ByVal nFlags As _
    UInt32) As Boolean
    Dim screenGrab As Bitmap

    Private Sub CaptureScreen()
    'captures Form1 into screenGrab
    screenGrab = New Bitmap(GroupBox1.Width, GroupBox1.Height)
    Dim g As Graphics = Graphics.FromImage(screenGrab)
    Dim hdc As IntPtr = g.GetHdc
    test.PrintWindow(GroupBox1.Handle, hdc, Nothing)

    g.ReleaseHdc(hdc)
    g.Flush()
    g.Dispose()

    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
    ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    ' page bounds are in 100ths of an inch...
    Dim pagewidth As Single = e.PageBounds.Width / 100
    Dim pageheight As Single = e.PageBounds.Height / 100
    ' how many pixels in the print area?
    Dim pagewidthpixels As Integer = pagewidth * e.PageSettings.PrinterResolution.X
    Dim pageheightpixels As Integer = pageheight * e.PageSettings.PrinterResolution.Y
    ' how many times does the screengrab image fit into the print area?
    Dim width_ratio As Double = pagewidthpixels / screenGrab.Width
    Dim height_ratio As Double = pageheightpixels / screenGrab.Height
    ' If the screengrab fits x times, then reduce the resolution of the printer by x.
    ' Only use one scaling_factor to keep it in proportion
    ' use the smaller of the two to keep it on the page
    Dim scaling_factor As Double
    If width_ratio > height_ratio Then
    scaling_factor = height_ratio
    Else
    scaling_factor = width_ratio
    End If
    ' set the resolution of the image - this will scale it to fit on the printed page
    screenGrab.SetResolution(e.PageSettings.PrinterRes olution.X / scaling_factor, e.PageSettings.PrinterResolution.Y / scaling_factor)
    ' send it to the printer
    e.Graphics.DrawImage(screenGrab, 0, 0)

    End Sub

  6. #6
    کاربر تازه وارد آواتار masysh
    تاریخ عضویت
    فروردین 1385
    پست
    79
    1. test چیه؟
    2. ممکنه بیشتر توضیح بدین؟

  7. #7
    به جای استفاده از دستور ShowDialog از دستور زیر استفاده کنید:

    rpt.PrintToPrinter(1, True, 1, 1)


    اولین پارامتر مربوط به تعداد چاپ می شود.

  8. #8
    کاربر دائمی آواتار ali_kolahdoozan
    تاریخ عضویت
    بهمن 1384
    محل زندگی
    اون سر دنیا
    پست
    1,631
    همش سه خط کد می خاد نه اینهمه

  9. #9
    کاربر تازه وارد آواتار jome ramezani
    تاریخ عضویت
    تیر 1385
    محل زندگی
    افغانستان
    پست
    55
    نقل قول نوشته شده توسط ali_kolahdoozan
    همش سه خط کد می خاد نه اینهمه
    اگه ممکنه این سه خط کد را در اینجا قرار دهید
    با تشکر

تاپیک های مشابه

  1. فرق form.showبا form.dialogsho
    نوشته شده توسط eshaghi در بخش C#‎‎
    پاسخ: 1
    آخرین پست: یک شنبه 07 بهمن 1386, 17:50 عصر
  2. گرفتن print از explorer بدون باز شدن پنجره print
    نوشته شده توسط abruee در بخش طراحی وب (Web Design)
    پاسخ: 4
    آخرین پست: چهارشنبه 08 فروردین 1386, 16:43 عصر
  3. چگونه خروجی Form.Print را به jpg ذخیره کنیم؟
    نوشته شده توسط Babak-Aghili در بخش کامپوننت های سایر شرکت ها، و توسعه کامپوننت
    پاسخ: 0
    آخرین پست: پنج شنبه 03 آذر 1384, 01:45 صبح
  4. refresh کردن master form از طریق detail form
    نوشته شده توسط mojtaba_abolhasani در بخش ASP.NET Web Forms
    پاسخ: 3
    آخرین پست: سه شنبه 24 شهریور 1383, 18:05 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •