Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-09-29
5
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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