I have design a form and set a label on form.
now i want to save a form a as a Tiff image any of a location.
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 Integer _
) As Boolean
End Function
Private Shared SRCCOPY As Integer = &HCC0020
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "C:\Users\KavtikP\Desktop\KpDesk\Test.Tiff"
SaveFormToFile(Me, path)
End Sub
Private Sub SaveFormToFile(ByVal sourceForm As Form, ByVal filename As String)
Dim formGraphics As Graphics = sourceForm.CreateGraphics()
Dim bufferRect = sourceForm.ClientRectangle
Dim buffer As Image = New Bitmap(bufferRect.Width, bufferRect.Height, formGraphics)
Dim bufferGraphics As Graphics = Graphics.FromImage(buffer)
Dim formDC As IntPtr = formGraphics.GetHdc()
Dim bufferDC As IntPtr = bufferGraphics.GetHdc()
BitBlt(bufferDC, 0, 0, bufferRect.Width, bufferRect.Height, formDC, 0, 0, SRCCOPY)
bufferGraphics.ReleaseHdc(bufferDC)
formGraphics.ReleaseHdc(formDC)
bufferGraphics.Dispose()
formGraphics.Dispose()
buffer.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff)
buffer.Dispose()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim screenRect As Rectangle = Screen.PrimaryScreen.WorkingArea
Dim myBitmapScreenShot = New Bitmap(screenRect.Width, screenRect.Height)
Using targetGraphics As Graphics = Graphics.FromImage(myBitmapScreenShot)
targetGraphics.CopyFromScreen(0, 0, 0, 0, New Size(myBitmapScreenShot.Width, myBitmapScreenShot.Height))
End Using
End Sub