PDA

View Full Version : print مستقیم form



shabrow
چهارشنبه 03 خرداد 1385, 08:07 صبح
سلام
می خواستم ببینم راهی هست که بدون باز شدن print preview و پنجره های دیگر فرم برنامه رو پرینت کرد :متفکر:

ali_kolahdoozan
چهارشنبه 03 خرداد 1385, 09:14 صبح
خوب priview نگیرید مستقیم printdocumnet رو چاپ کنید

shabrow
شنبه 06 خرداد 1385, 00:19 صبح
ممنون میشم اگه یه مثال ساده برام بزنید

setak
شنبه 06 خرداد 1385, 11:04 صبح
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

setak
شنبه 06 خرداد 1385, 11:05 صبح
کد زیر را مطالعه کنید . اگر متوجه نشدید 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

masysh
شنبه 06 خرداد 1385, 18:39 عصر
1. test چیه؟
2. ممکنه بیشتر توضیح بدین؟

shima818
دوشنبه 08 خرداد 1385, 18:03 عصر
به جای استفاده از دستور ShowDialog از دستور زیر استفاده کنید:


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

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

ali_kolahdoozan
دوشنبه 08 خرداد 1385, 21:42 عصر
همش سه خط کد می خاد نه اینهمه

jome ramezani
پنج شنبه 25 آبان 1385, 08:54 صبح
همش سه خط کد می خاد نه اینهمه
اگه ممکنه این سه خط کد را در اینجا قرار دهید
با تشکر