PDA

View Full Version : چاپ فرم با تمام متعلقات(form.printform)



Ehsan Zand
یک شنبه 09 مرداد 1384, 12:36 عصر
سلام
از اونجایی که vb.net از form.printform که در vb6 بود پشتیبانی نمی کنه
آیا راهی هست که تمام فرم رو به صورت مثلا عکس چاپ کنیم
اگر کسی کدی در این مورد داره خواهشا برام بنویسه که خیلی بهش احتیاج دارم.
ممنون.

H_Ghaffarian
یک شنبه 30 مرداد 1384, 07:58 صبح
سلام
نمونه کامل این کد رو می تونید توی Msdn پیدا کنید.

Ehsan Zand
یک شنبه 30 مرداد 1384, 15:19 عصر
سلام این تاپیک مال 1 ماه پیش بود که کسی جواب مارو نداد. ولی بازم ممنون.
خودم همون موقع جوابش رو به چند روش مختلف وکد های گوناگون پیدا کرم و مشکلم حل شد
ولی چون زیاد بود دیگه اینجا نزاشتمش. اگه بازم کسی مشکل داشت بگه کدها رو بفرستم.

Peyman_Ranjbar
دوشنبه 31 مرداد 1384, 08:47 صبح
یه سورس کد در این زمینه دارم ولی به #C هست

به دردت می خوره؟:p

Ehsan Zand
سه شنبه 01 شهریور 1384, 02:17 صبح
سلام به همگی
آقا محسن و بقیه دوستان، اختیار دارید. همگی حق استادی به گردن ما دارید. اینم کدهای چاپ فرم
و برخی منابع آنها:
اولیش:



' create a printing component
Private WithEvents pd As Printing.PrintDocument
' storage for form image
Dim formImage As Bitmap
' create API prototype
Private Declare Function BitBlt Lib "gdi32.dll" Alias _
"BitBlt" (ByVal hdcDest 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 Long

' Callback from PrintDocument component to
' do the actual printing
Private Sub pd_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles pd.PrintPage
e.Graphics.DrawImage(formImage, 100, 100)
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' create an instance of the PrintDocument component
pd = New Printing.PrintDocument
Me.StartPosition = FormStartPosition.CenterScreen
End Sub

Private Sub btnPrintForm_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles btnPrintForm.Click
' initiate the printdocument component
GetFormImage()
pd.Print()
End Sub

Private Sub GetFormImage()
Dim g As Graphics = MeCreateGraphics()
Dim s As Size = Me.Size
formImage = New Bitmap(s.Width, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
' added code to compute and capture the form
' title bar and borders
Dim widthDiff As Integer = _
(Me.Width - Me.ClientRectangle.Width)
Dim heightDiff As Integer = _
(Me.Height - Me.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, _
Me.ClientRectangle.Width + widthDiff, _
Me.ClientRectangle.Height + heightDiff, dc1, _
0 - borderSize, 0 - heightTitleBar, 13369376)

g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)
End Sub

منبع :



http://www.knowdotnet.com/articles/printform.html

Ehsan Zand
سه شنبه 01 شهریور 1384, 02:20 صبح
دومیش: ( فکر کنم خودم از این استفاده کردم چون از بقیه بهتر بود)



Imports System.Drawing

' ...

Private Const SRCCOPY As Integer = &HCC0020

Private Declare Function BitBlt _
Lib "gdi32.dll" ( _
ByVal hdcDest As IntPtr, _
ByVal x As Int32, _
ByVal y As Int32, _
ByVal Width As Int32, _
ByVal Height As Int32, _
ByVal hdcSrc As IntPtr, _
ByVal xSrc As Int32, _
ByVal ySrc As Int32, _
ByVal dwRop As Int32 _
) As Boolean

Private formImage As Bitmap

Public Sub PrintForm(Optional ByVal fullWindow As Boolean = False)

With Me ' This can easily be replaced with a Form parameter

' Create a Graphics object for the form
Dim formGraphics As Graphics = .CreateGraphics

' Create a compatible bitmap and get its Graphics object
If fullWindow Then
formImage = New Bitmap(.Width, .Height, formGraphics)
Else
formImage = New Bitmap(.ClientRectangle.Width, _
.ClientRectangle.Height, _
formGraphics)
End If
Dim memGraphics As Graphics = Graphics.FromImage(formImage)

' Get the target and source device context handles (hDC)
Dim sourceDC As IntPtr = formGraphics.GetHdc
Dim targetDC As IntPtr = memGraphics.GetHdc

' Do the screenshot part of the job
If fullWindow Then

' Consider the border width and the titlebar height
Dim widthDelta As Integer = (.Width - _
.ClientRectangle.Width)
Dim heightDelta As Integer = (.Height - _
.ClientRectangle.Height)
' Copy the form including its titlebar and borders
BitBlt(targetDC, _
0, 0, _
.ClientRectangle.Width + widthDelta, _
.ClientRectangle.Height + heightDelta, _
sourceDC, _
0 - widthDelta \ 2, 0 - (heightDelta - widthDelta \ 2), _
SRCCOPY)

Else

' Copy the form's client area
BitBlt(targetDC, _
0, 0, .ClientRectangle.Width, .ClientRectangle.Height, _
sourceDC, _
.ClientRectangle.X, .ClientRectangle.Y, _
SRCCOPY)

End If

' Release DCs and dispose objects
formGraphics.ReleaseHdc(sourceDC)
formGraphics.Dispose()
memGraphics.ReleaseHdc(targetDC)
memGraphics.Dispose()

' formImage now has the form's image. Print it before disposing it.
PrintDocument1.Print() ' Invokes PrintDocument1_PrintPage (below)

' Finally dispose the image
formGraphics.Dispose()

End With

End Sub

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

' Print the screen shot in formImage. Use DrawImage's
' parameters to control the position of the printer output.
e.Graphics.DrawImage(formImage, 100, 200) ' printing position x=100, y=200

End Sub
منبع : یه چیزی تو این مایه هاست:
http://weblogs.asp.net/mschiffer/archive/2004/07/13/181111.aspx
اینجا هم هست:
http://www.a1vbcode.com/vbforums/shwmessage.aspx?ForumID=9&MessageID=12904


سومیش: فقط منبعش رو میزارم اگه خواستید برید ببینید:
http://www.developerfusion.co.uk/forums/topic-23064

Ehsan Zand
سه شنبه 01 شهریور 1384, 02:31 صبح
اینم چند تا برنامه نمونه :
که این (printforminstaller.rar ) یه کامپوننت پولیه که خیلی خفنه. می تونه از فرمهای Hide هم حتی چند فرم Hide به صورت همزمان پرینت بگیره و نمی دونم چه کار کردند که کیفیت تصویر هم بسیار عالیه و پایین نمیاد. چون همون طور که میدونید پرینت گرفتن از فرم خیلی وابسته به رزلوشنه و از یه حدی بهتر نمیشه.
امتحان کنید.
درضمن خداییش هر کی crack این کامپوننت رو گیر آورد یه ندا هم به ما بده که کارمون سر کیفیت تصویر هنوز گیره. (با تشکر از آقای مدیر که این قسمت رو حذف نکرده).
در ضمن نمونه کد این کامپوننت هم در حالتهای مختلف استفاده تو فایل بعدی
(PrintForm Printing Component.rar) هست.
آقایون و خانمها امیدوارم لذت واستفاده ببرید و راضی شده باشید چون پدرم دراومد تا
این فایلا رو آپلود کردم. (مخصوصا آقا محسن).

mehrdotnet
سه شنبه 01 شهریور 1384, 09:14 صبح
جالب بود!
دستتون درد نکنه. از اینکه صادقانه برای ما و دوستانتون زحمت می کشین متشکریم.