Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

My customer needs to view a captured image of the input form.

Posted on 2008-09-29
5
Medium Priority
?
236 Views
Last Modified: 2013-11-26
I have used VB to create an application with a user interface that needs to be viewed as an image.  My customer inputs several parameters and selections to initiate analysis but needs to view the input at a later date and would like it to be an image.  In the past I have used SendKeys.Send("({PRTSC})") but that is unrelable and doesn't work this time.  

The user doesn't have any application tools on their PC.

Does anyone know how to save a form as an image?
0
Comment
Question by:fsoucy
5 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22596422
have you checked
e.Graphics.CopyFromScreen(...) method?
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 22596430
Try the code below. The form itself (as well as any other control in .net framework 2.0 and above) has a method called DrawToBitmap.
Imports System.Drawing
Imports System.Drawing.Imaging
 
Public Class Form1
    Public Sub SaveFormImage(ByVal Path As String)
        'Create a new empty bitmap with form dimensions
        Dim oBitmap As New Bitmap(Me.Width, Me.Height)
        'Create a rectangle with form bounds
        Dim rect As New Rectangle(0, 0, Me.Width, Me.Height)
        'Draw the form onto the bitmap
        Me.DrawToBitmap(oBitmap, rect)
        'Save the bitmap in JPEG format
        oBitmap.Save(Path, ImageFormat.Jpeg)
        'Dispose the bitmap (no more needed)
        oBitmap.Dispose()
    End Sub
End Class

Open in new window

0
 
LVL 3

Expert Comment

by:Diveblue
ID: 22596483
<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _
    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
    End Function

    Private Sub CaptureForm()
        Dim g1 As Graphics = Me.CreateGraphics()
        Dim MyImage As Bitmap = 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)
        MyImage.Save("c:\temp\foo.jpg")
        MessageBox.Show("Finished Saving Image")
    End Sub 'Capture_Click
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 22596679
Hi fsoucy;

This snippet will do what you need.

        Dim controlImage As Bitmap = New Bitmap(Me.Width, Me.Height, Me.CreateGraphics())
        Dim g As Graphics = Graphics.FromImage(controlImage)
        g.CopyFromScreen(Me.Location, New Point(0, 0), New Size(Me.Width, Me.Height))
        controlImage.Save("MainForm.jpg", Imaging.ImageFormat.Jpeg)
        controlImage = Nothing
        g.Dispose()

Fernando
0
 

Author Closing Comment

by:fsoucy
ID: 31501166
This was easy, thanks.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question