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
Solved

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

Posted on 2008-09-29
5
226 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 500 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 63

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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