net 2010 and I have the following code which brings the panel and its contents to a printer but every time I try to convert the panel into a PDF form the pd.Print() in the button click always returns a nullreferencedunhandled any idea on ho to fix this??
thanks
Public Class Form1
Dim img As Bitmap
Dim WithEvents pd As PrintDocument
'Returns the Form as a bitmap
Function CaptureForm1() As Bitmap
Dim g1 As Graphics = Me.CreateGraphics()
Dim MyImage = New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1)
Dim g2 As Graphics = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr = g1.GetHdc()
Dim dc2 As IntPtr = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
'saves image to c drive just, u can comment it also
'MyImage.Save("c:\abc.bmp")
Return MyImage
End Function
<DllImport("gdi32.DLL", EntryPoint:="BitBlt", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function 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 Boolean
' Leave function empty - DLLImport attribute forwards calls to MoveFile to
' MoveFileW in KERNEL32.DLL.
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'img = CaptureForm1()
'pd = New PrintDocument
'pd.Print()
Dim PrintDialog1 As New PrintDialog()
PrintDialog1.Document = pd
Dim result As DialogResult = PrintDialog1.ShowDialog()
If (result = DialogResult.OK) Then
pd.Print()
End If
End Sub
'this method will be called each time when pd.printpage event occurs
Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage
Dim x As Integer = e.MarginBounds.X
Dim y As Integer = e.MarginBounds.Y
e.Graphics.DrawImage(img, x, y)
e.HasMorePages = False
End Sub
End Class
Related
I was using hot keys, but out of nowhere, they are not working anymore. It's very confusing.
It happened when my friend checked my code through team-viewer. Then it stopped working.
Public Class Form2
Public Const MOD_ALT As Integer = &H1 'Alt key
Public Const WM_HOTKEY As Integer = &H312
<DllImport("User32.dll")> _
Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _
ByVal id As Integer, ByVal fsModifiers As Integer, _
ByVal vk As Integer) As Integer
End Function
<DllImport("User32.dll")> _
Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _
ByVal id As Integer) As Integer
End Function
Private Sub Form2_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle, 100, MOD_ALT, Keys.E)
RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.A)
Me.TopMost = True
Me.ShowInTaskbar = False
Me.TransparencyKey = Me.BackColor
Dim leftpos As Long
Dim toppos As Long
leftpos = (My.Computer.Screen.WorkingArea.Right - 2) - Me.Width
toppos = (My.Computer.Screen.WorkingArea.Bottom - 2) - Me.Height
Me.Location = New Point(leftpos, toppos)
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
Dim id As IntPtr = m.WParam
Select Case (id.ToString)
Case "100"
Application.Exit()
Case "200"
Form3.Show()
End Select
End If
MyBase.WndProc(m)
End Sub
Private Sub Form2_FormClosing(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles MyBase.FormClosing
UnregisterHotKey(Me.Handle, 100)
UnregisterHotKey(Me.Handle, 200)
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Form3.Show()
Form3.Activate()
End If
End Sub
End Class
i fixed some api function signatures with the help of a good guy IronRazer in dreamincode as per the below
<DllImport("user32.dll", EntryPoint:="RegisterHotKey")> _
Private Shared Function RegisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll", EntryPoint:="UnregisterHotKey")> _
Private Shared Function UnregisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
and it worked fine.
Using VB.Net 2012
I would like to put a command button on the of my windows form to the left of the control box and to the right of the title. Is this possible?
I don't see a way of doing this through the 'standard' windows means perhaps with some more advanced GDI trickery?
I was going to add a picture of what I am trying to accomplish but apparently my reputation is too low to post images, I will try an ascii picture, please use your imagination!
________________________________________________________
|Q Windows Title [New BUTTON] [ _ O X ] |
|______________________________________________________|
| |
| Normal windows area |
It has some work but can be done. Create a new class APIHelp:
Imports System.Runtime.InteropServices
Public Class APIHelp
Public Const WS_EX_LAYERED As Int32 = 524288
'Public Const HTCAPTION As Int32 = 2
'Public Const WM_NCHITTEST As Int32 = 132
Public Const ULW_ALPHA As Int32 = 2
Public Const AC_SRC_OVER As Byte = 0
Public Const AC_SRC_ALPHA As Byte = 1
Public Enum Bool
[False] = 0
[True] = 1
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure Point
Public x As Int32
Public y As Int32
Public Sub New(ByVal x As Int32, ByVal y As Int32)
Me.x = x
Me.y = y
End Sub
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure Size
Public cx As Int32
Public cy As Int32
Public Sub New(ByVal cx As Int32, ByVal cy As Int32)
Me.cx = cx
Me.cy = cy
End Sub
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Private Structure ARGB
Public Blue As Byte
Public Green As Byte
Public Red As Byte
Public Alpha As Byte
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure BLENDFUNCTION
Public BlendOp As Byte
Public BlendFlags As Byte
Public SourceConstantAlpha As Byte
Public AlphaFormat As Byte
End Structure
Public Declare Auto Function UpdateLayeredWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Point, ByRef psize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, _
ByVal crKey As Int32, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Int32) As Bool
Public Declare Auto Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As IntPtr) As IntPtr
Public Declare Auto Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
<DllImport("user32.dll", ExactSpelling:=True)> _
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
Public Declare Auto Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Bool
<DllImport("gdi32.dll", ExactSpelling:=True)> _
Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
End Function
Public Declare Auto Function DeleteObject Lib "gdi32.dll" (ByVal hObject As IntPtr) As Bool
End Class
Add a new form eg Form2. Set TopMost = False, FormBorderStyle = None and
ShowInTaskbar = False. This form will be your button. Because we want to draw tranparently we set the WS_EX_LAYERED style and we draw
with UpdateLayeredWindow function. You can not draw directly on a form with WS_EX_LAYERED style.
You have to use a device context, draw in it and then call UpdateLayeredWindow:
Public Class Form2
Private sourceLocation As New APIHelp.Point(0, 0)
Private newSize As New APIHelp.Size(...., .....)
Private newLocation As APIHelp.Point
Private blend As New APIHelp.BLENDFUNCTION()
Private memDcNormal, memDcEnter, memDcDown, screenDc, hBmpNormal, hBmpNormalOld, _
hBmpEnter, hBmpEnterOld, hBmpDown, hBmpDownOld As IntPtr
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Location = New Point(Form1.Location.X + ..., Form1.Location.Y + ...) 'complete the dots
Me.Size = New Size(..., ...) 'size of button
Initialize()
End Sub
Private Sub Initialize()
' Only works with a 32bpp bitmap
blend.BlendOp = APIHelp.AC_SRC_OVER
' Always 0
blend.BlendFlags = 0
' Set to 255 for per-pixel alpha values
blend.SourceConstantAlpha = 255
' Only works when the bitmap contains an alpha channel
blend.AlphaFormat = APIHelp.AC_SRC_ALPHA
screenDc = APIHelp.GetDC(IntPtr.Zero)
Using bmp As Bitmap = CType(Bitmap.FromFile(".....Normal.png"), Bitmap)
memDcNormal = IntPtr.Zero
memDcNormal = APIHelp.CreateCompatibleDC(screenDc)
hBmpNormal = bmp.GetHbitmap(Color.FromArgb(0))
hBmpNormalOld = APIHelp.SelectObject(memDcNormal, hBmpNormal)
End Using
Using bmp As Bitmap = CType(Bitmap.FromFile("......Enter.png"), Bitmap)
memDcEnter = IntPtr.Zero
memDcEnter = APIHelp.CreateCompatibleDC(screenDc)
hBmpEnter = bmp.GetHbitmap(Color.FromArgb(0))
hBmpEnterOld = APIHelp.SelectObject(memDcEnter, hBmpEnter)
End Using
Using bmp As Bitmap = CType(Bitmap.FromFile("......Down.png"), Bitmap)
memDcDown = IntPtr.Zero
memDcDown = APIHelp.CreateCompatibleDC(screenDc)
hBmpDown= bmp.GetHbitmap(Color.FromArgb(0))
hBmpDownOld = APIHelp.SelectObject(memDcDown, hBmpDown)
End Using
APIHelp.DeleteDC(screenDc)
End Sub
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
'Add the layered extended style (WS_EX_LAYERED) to this window
Dim createParam As CreateParams = MyBase.CreateParams
createParam.ExStyle = createParam.ExStyle Or 524288 'WS_EX_LAYERED
Return createParam
End Get
End Property
Private Sub Form2_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
newLocation = New APIHelp.Point(Me.Location.X, Me.Location.Y)
APIHelp.UpdateLayeredWindow(Handle, IntPtr.Zero, newLocation, newSize, memDcDown, sourceLocation, _
0, blend, APIHelp.ULW_ALPHA)
End Sub
Private Sub Form2_MouseEnter(sender As System.Object, e As System.EventArgs) Handles MyBase.MouseEnter
newLocation = New APIHelp.Point(Me.Location.X, Me.Location.Y)
APIHelp.UpdateLayeredWindow(Handle, IntPtr.Zero, newLocation, newSize, memDcEnter, sourceLocation, _
0, blend, APIHelp.ULW_ALPHA)
End Sub
Private Sub Form2_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Static i As Integer = 1
Static j As Integer = 1
If e.Button = Windows.Forms.MouseButtons.Left Then
If e.X < 0 Or e.X > Me.Width Or e.Y < 0 Or e.Y > Me.Height Then
If i = 1 Then
newLocation = New APIHelp.Point(Me.Location.X, Me.Location.Y)
APIHelp.UpdateLayeredWindow(Handle, IntPtr.Zero, newLocation, newSize, memDcNormal, sourceLocation, _
0, blend, APIHelp.ULW_ALPHA)
i = 0
j = 1
End If
Else
If j = 1 Then
newLocation = New APIHelp.Point(Me.Location.X, Me.Location.Y)
APIHelp.UpdateLayeredWindow(Handle, IntPtr.Zero, newLocation, newSize, memDcDown, sourceLocation, _
0, blend, APIHelp.ULW_ALPHA)
j = 0
i = 1
End If
End If
End If
End Sub
Private Sub Form2_MouseLeave(sender As System.Object, e As System.EventArgs) Handles MyBase.MouseLeave
newLocation = New APIHelp.Point(Me.Location.X, Me.Location.Y)
APIHelp.UpdateLayeredWindow(Handle, IntPtr.Zero, newLocation, newSize, memDcNormal, sourceLocation, _
0, blend, APIHelp.ULW_ALPHA)
End Sub
Private Sub Form2_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseClick
newLocation = New APIHelp.Point(Me.Location.X, Me.Location.Y)
APIHelp.UpdateLayeredWindow(Handle, IntPtr.Zero, newLocation, newSize, memDcEnter, sourceLocation, _
0, blend, APIHelp.ULW_ALPHA)
'Do your staff
End Sub
Private Sub Form2_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
APIHelp.SelectObject(memDcNormal, hBmpNormalOld)
APIHelp.DeleteObject(hBmpNormal)
APIHelp.DeleteDC(memDcNormal)
APIHelp.SelectObject(memDcEnter, hBmpEnterOld)
APIHelp.DeleteObject(hBmpEnter)
APIHelp.DeleteDC(memDcEnter)
APIHelp.SelectObject(memDcDown, hBmpDownOld)
APIHelp.DeleteObject(hBmpDown)
APIHelp.DeleteDC(memDcDown)
End Sub
End Class
As you can see from the above code you need three png images for each state of the button.
In your initial form:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Form2.Show(Me)
End Sub
Private Sub Form1_Move(sender As System.Object, e As System.EventArgs) Handles MyBase.Move
Form2.Location = New Point(Me.Location.X + ..., Me.Location.Y + ...)
End Sub
valter
hi I have this code that will send my panel into a printer but the problem is it doesent let me choose which printer I will use any idea on how can I make the printer window appear?
thanks
Public Class Form1
Dim img As Bitmap
Dim WithEvents pd As PrintDocument
'Returns the Form as a bitmap
Function CaptureForm1() As Bitmap
Dim g1 As Graphics = Me.CreateGraphics()
Dim MyImage = New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1)
Dim g2 As Graphics = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr = g1.GetHdc()
Dim dc2 As IntPtr = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
'saves image to c drive just, u can comment it also
'MyImage.Save("c:\abc.bmp")
Return MyImage
End Function
<DllImport("gdi32.DLL", EntryPoint:="BitBlt", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function 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 Boolean
' Leave function empty - DLLImport attribute forwards calls to MoveFile to
' MoveFileW in KERNEL32.DLL.
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
img = CaptureForm1()
pd = New PrintDocument
pd.Print()
End Sub
'this method will be called each time when pd.printpage event occurs
Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage
Dim x As Integer = e.MarginBounds.X
Dim y As Integer = e.MarginBounds.Y
e.Graphics.DrawImage(img, x, y)
e.HasMorePages = False
End Sub
End Class
i've found this code on the web that allow me to draw a rectangle and keep the Image inside this. But there is a way to make draw this rectangle in all the direction and not only from left to right and top to bottom?
Thank for the help!
Here is the code:
Public Class frmSS
Private Declare Auto Function BitBlt Lib "gdi32.dll" ( _
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 Int32) As Boolean
Private Declare Auto Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Auto Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As IntPtr
Private Sub frmSS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.Location = New Point(0, 0)
Me.ClientSize = Screen.GetBounds(Me).Size
Me.BackColor = Color.Gray
Me.DoubleBuffered = True
Me.Opacity = 0.4#
Me.Cursor = Cursors.Cross
Me.ShowInTaskbar = False
End Sub
Private isDragging As Boolean = False
Private canDrag As Boolean = True
Private pt_start As Point = Point.Empty
Private pt_end As Point = Point.Empty
Private Sub frmSS_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If Me.canDrag Then
Me.isDragging = True
Me.pt_start = e.Location
End If
End Sub
Private Sub frmSS_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Me.isDragging Then
Me.pt_end = e.Location
Me.Invalidate()
End If
End Sub
Private Sub frmSS_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If Me.isDragging Then
Me.isDragging = False
Me.canDrag = False
Me.Cursor = Cursors.Default
Dim r As Rectangle = Me.SelectedRectangle
Me.Hide()
Application.DoEvents() 'Make sure everything's good and hidden.
Me.CaptureThisArea(r)
Me.Close()
End If
End Sub
Private ReadOnly Property SelectedRectangle() As Rectangle
Get
With pt_start
If .X >= pt_end.X OrElse .Y >= pt_end.Y Then Return Rectangle.Empty
Return New Rectangle(.X, .Y, pt_end.X - .X, pt_end.Y - .Y)
End With
End Get
End Property
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
Using p As New Pen(Color.Black, 3)
p.DashStyle = Drawing2D.DashStyle.Dash
If Me.SelectedRectangle <> Rectangle.Empty Then
g.FillRectangle(Brushes.Red, Me.SelectedRectangle)
g.DrawRectangle(p, Me.SelectedRectangle)
End If
End Using
MyBase.OnPaint(e)
End Sub
Private Sub CaptureThisArea(ByVal area As Rectangle)
Dim bmp As New Bitmap(area.Width, area.Height, Imaging.PixelFormat.Format24bppRgb)
Using g As Graphics = Graphics.FromImage(bmp)
Dim srcDC As IntPtr = GetDC(IntPtr.Zero)
Dim destDC As IntPtr = g.GetHdc()
BitBlt(destDC, 0, 0, area.Width, area.Height, srcDC, area.X, area.Y, 13369376) 'SRCCOPY = 13369376
g.ReleaseHdc(destDC)
ReleaseDC(IntPtr.Zero, srcDC)
End Using
Dim s_dl As New SaveFileDialog()
s_dl.Filter = "Bitmap Images (*.bmp)|*.bmp"
If s_dl.ShowDialog() = DialogResult.Cancel Then Exit Sub
bmp.Save(s_dl.FileName)
MessageBox.Show("File saved!!!")
End Sub
End Class
You need to try to determine the rectangle based on the initial MouseDown point and during the MouseMove, see if the current mouse coordinates need to be adjusted based on minimums and maximums of each X and Y value:
Comment out pt_end and add a dragRect variable:
'\\ Private pt_end As Point = Point.Empty
Private dragRect As Rectangle = Rectangle.Empty
Change your MouseMove event to this:
Private Sub frmSS_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove
If Me.isDragging Then
Dim minPoint As New Point(Math.Min(e.Location.X, pt_start.X), _
Math.Min(e.Location.Y, pt_start.Y))
Dim maxPoint As New Point(Math.Max(e.Location.X, pt_start.X), _
Math.Max(e.Location.Y, pt_start.Y))
dragRect = New Rectangle(minPoint, New Size(maxPoint.X - minPoint.X, _
maxPoint.Y - minPoint.Y))
Me.Invalidate()
End If
End Sub
From there, change your code to use dragRect instead of SelectedRectangle, which I commented out.
i am developing a project in which i have to print a bill on purchase.
I have a special header pad for all bills that's why, how can i do so....
that all the time......it maintain.......
I have a form for make bills.........
i don't know how to print it......
How can i fetch a data and using which dialog box i can do(print) it........
I am using vs2010 ......
How can i do...........
PrintDialog printDialog1 = new PrintDialog()
printDialog1.Document = printDocument1;
DialogResult result = printDialog1.ShowDialog(this);
if (result == DialogResult.OK)
{
printDocument1.Print();
}
Public Class Form1
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 Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pd = New Printing.PrintDocument
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetFormImage()
pd.Print()
End Sub
Private Sub GetFormImage()
Dim g As Graphics = Me.CreateGraphics()
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
End Class