Printing Component Advice
-
I have a need to print a Form and its ComboBoxes and Labels by way of a ButtonClick. I found an example to use but it's very vague and I've been told that you can't code a Button in a Form to Print without an aftermarket tool. Any advice? Thanks Jason -- modified at 16:29 Wednesday 7th February, 2007
-
I have a need to print a Form and its ComboBoxes and Labels by way of a ButtonClick. I found an example to use but it's very vague and I've been told that you can't code a Button in a Form to Print without an aftermarket tool. Any advice? Thanks Jason -- modified at 16:29 Wednesday 7th February, 2007
here is an easy way: Dim bm As New Bitmap(Me.Width, Me.Height) Dim g As Graphics = Graphics.FromImage(bm) Me.DrawToBitmap(bm, New Rectangle(0, 0, Me.Width, Me.Height)) now you can customize this code to getting a bitmap that only contain client rectangle of your form. another way is: Public Class ScreenCapture _ Private Shared Function GetDesktopWindow() As IntPtr End Function _ Private Shared Function GetWindowDC(ByVal hwnd As IntPtr) As IntPtr End Function _ Private Shared Function BitBlt(ByVal hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As System.Int32) As UInt64 End Function 'Save the screen capture into a jpg Public Shared Function SaveScreen() As Bitmap Dim myImage = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim gr1 As Graphics = Graphics.FromImage(myImage) Dim dc1 As IntPtr = gr1.GetHdc() Dim dc2 As IntPtr = ScreenCapture.GetWindowDC(ScreenCapture.GetDesktopWindow()) ScreenCapture.BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376) gr1.ReleaseHdc(dc1) Return myImage End Function 'SaveScreen End Class 'NativeMethods
-
here is an easy way: Dim bm As New Bitmap(Me.Width, Me.Height) Dim g As Graphics = Graphics.FromImage(bm) Me.DrawToBitmap(bm, New Rectangle(0, 0, Me.Width, Me.Height)) now you can customize this code to getting a bitmap that only contain client rectangle of your form. another way is: Public Class ScreenCapture _ Private Shared Function GetDesktopWindow() As IntPtr End Function _ Private Shared Function GetWindowDC(ByVal hwnd As IntPtr) As IntPtr End Function _ Private Shared Function BitBlt(ByVal hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As System.Int32) As UInt64 End Function 'Save the screen capture into a jpg Public Shared Function SaveScreen() As Bitmap Dim myImage = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim gr1 As Graphics = Graphics.FromImage(myImage) Dim dc1 As IntPtr = gr1.GetHdc() Dim dc2 As IntPtr = ScreenCapture.GetWindowDC(ScreenCapture.GetDesktopWindow()) ScreenCapture.BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376) gr1.ReleaseHdc(dc1) Return myImage End Function 'SaveScreen End Class 'NativeMethods
I tried both methods and the first one was promising, although nothing happened. The Second example gave me a bunch of errors. I found a topic on this very same subject and ended up downloading a ToolPack to get the "PrintForm" component. I set the PrintAction property to PrintToPrinter and put PrintForm1.Print() in the event handler for the Button. This got me the print! Thanks for the help. -- modified at 9:37 Thursday 8th February, 2007