-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: HuntingBhadri
Message 1 in Discussion

I have a problem in printing large windows form. I have used following code to 
print the form. still  it's printing like print screen, not complete  form. 
Form is larger than the Screen and Scrollable.    
Private Const SRCCOPY As Integer = &HCC0020 
' 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 
Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles BtnPrint.Click 
' initiate the printdocument component 
GetFormImage(True) 
' pd.Print() 
End Sub 
' 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, 0, 0) 
' e.HasMorePages = True 
End Sub 
Private Sub GetFormImage(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. 
pd.Print() ' Invokes PrintDocument1_PrintPage (below) 
' Finally dispose the image 
formGraphics.Dispose() 
End With 
  
please help me out. Any solution would be great.  
Thanks in advance. 
Regards 
Bhadri

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to