Newbie to VB.net
I'm trying to find a replacement for Vb Printform think I may have found it.....
this will not compile: could someone walk me through the setup of this?
I created new project with one form on it Form1 in the code area I put the following::
Public
Class Form1Imports System.Drawing' ...PrivateConst SRCCOPYAsInteger = &HCC0020PrivateDeclareFunction BitBlt _Lib"gdi32.dll" ( _ByVal hdcDestAs IntPtr, _ByVal xAs Int32, _ByVal yAs Int32, _ByVal WidthAs Int32, _ByVal HeightAs Int32, _ByVal hdcSrcAs IntPtr, _ByVal xSrcAs Int32, _ByVal ySrcAs Int32, _ByVal dwRopAs Int32 _)
AsBooleanPrivate formImageAs BitmapPublicSub PrintForm(OptionalByVal fullWindowAsBoolean =False)' Copyright ? 2004 by Mathias Schiffer. Leave this notice in place.' Copies a screenshot of the form this code is being run in' to the active printer. Place this code in a form module.' Set fullWindow to True for including borders and titlebar.' Remember to use an Imports reference to System.Drawing.' Also, add a PrintDocument1 control to the form for printing.' The disadvantage of this code is that it does only capture' those parts of the form that are actually visible (screenshot),' i.e. it must not be hidden and may not even be obscured.' VB's PrintForm method does not require that, so this is not a' perfect replacement. Keep that in mind.WithMe' This can easily be replaced with a Form parameter' Create a Graphics object for the formDim formGraphicsAs Graphics = .CreateGraphics' Create a compatible bitmap and get its Graphics objectIf fullWindowThenformImage =
New Bitmap(.Width, .Height, formGraphics)ElseformImage =
New Bitmap(.ClientRectangle.Width, _.ClientRectangle.Height, _
formGraphics)
EndIfDim memGraphicsAs Graphics = Graphics.FromImage(formImage)' Get the target and source device context handles (hDC)Dim sourceDCAs IntPtr = formGraphics.GetHdcDim targetDCAs IntPtr = memGraphics.GetHdc' Do the screenshot part of the jobIf fullWindowThen' Consider the border width and the titlebar heightDim widthDeltaAsInteger = (.Width - _.ClientRectangle.Width)
Dim heightDeltaAsInteger = (.Height - _.ClientRectangle.Height)
' Copy the form including its titlebar and bordersBitBlt(targetDC, _
0, 0, _
.ClientRectangle.Width + widthDelta, _
.ClientRectangle.Height + heightDelta, _
sourceDC, _
0 - widthDelta \ 2, 0 - (heightDelta - widthDelta \ 2), _
SRCCOPY)
Else' Copy the form's client areaBitBlt(targetDC, _
0, 0, .ClientRectangle.Width, .ClientRectangle.Height, _
sourceDC, _
.ClientRectangle.X, .ClientRectangle.Y, _
SRCCOPY)
EndIf' Release DCs and dispose objectsformGraphics.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 imageformGraphics.Dispose()
EndWithEndSubPrivateSub PrintDocument1_PrintPage( _ByVal senderAs System.Object, _ByVal eAs 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=200EndSubEnd
ClassI get three errors line 2 Imports must proceed declarations
line 90 PrintDocument1 not declared
line 102 Handle requires WithEvent.
I'm sure its something simple but with the Vb.Net I don;t know thanks
Mitch

