Solved

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

Posted on 2008-09-29
5
220 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
Comment Utility
have you checked
e.Graphics.CopyFromScreen(...) method?
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
Comment Utility
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
Comment Utility
<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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
This was easy, thanks.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now