Form Attachment

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 603 Views - Last Post: 25 January 2014 - 12:09 PM Rate Topic: -----

#16 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3479
  • View blog
  • Posts: 11,825
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 10:35 AM

The code is a sub-procedure, also called a method. It has two parameters.

  • How do you call a procedure?
  • How do you supply arguments when calling a procedure?

If you don't understand these things then there are significant gaps in your VB knowledge. You need to understand these things before you attempt to build an application.
Was This Post Helpful? 1
  • +
  • -

#17 rjames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-January 14

Re: Form Attachment

Posted 25 January 2014 - 10:47 AM

I know how to do both of these things, however I can't call a Private Subroutine.

I think I've found a conclusive piece of code that does what I need:
Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
        Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
        gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
        bmpScreenshot.Save("D:\InvoiceForm.jpg", ImageFormat.Jpeg)


This goes inside of a button, called capture in the form before the E-Mail Form.

Then. because I already know the name of the file I can do this:
Dim attachment As New Attachment("D:\InvoiceForm.jpg")
            E_Mail.Attachments.Add(attachment)


In the actual E-Mail form.

However, I get an error here:
 bmpScreenshot.Save("D:\InvoiceForm.jpg", ImageFormat.Jpeg)

It states: an external exception was unhandled.
A generic error occured in GDI+
Was This Post Helpful? 0
  • +
  • -

#18 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3479
  • View blog
  • Posts: 11,825
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 10:59 AM

That code works for me if I don't specify the PixelFormat or attempt to write directly to the D: (or C:) drive:

        Dim bmpScreenshot As Bitmap = New Bitmap(400, 400)
        Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
        gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
        bmpScreenshot.Save("InvoiceForm.jpg", ImageFormat.Jpeg)

Was This Post Helpful? 1
  • +
  • -

#19 rjames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-January 14

Re: Form Attachment

Posted 25 January 2014 - 11:42 AM

View Postandrewsw, on 25 January 2014 - 10:59 AM, said:

That code works for me if I don't specify the PixelFormat or attempt to write directly to the D: (or C:) drive:

        Dim bmpScreenshot As Bitmap = New Bitmap(400, 400)
        Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
        gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
        bmpScreenshot.Save("InvoiceForm.jpg", ImageFormat.Jpeg)


I've changed the first line to this:
Dim bmpScreenshot As Bitmap = New Bitmap(771, 582)

However the error I mentioned above has repeated itself, I put in the size of the form instead of 400 x 400 because when it takes a print screen it only takes a screen capture of a small size of the form instead of the entire thing?
Was This Post Helpful? 0
  • +
  • -

#20 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3479
  • View blog
  • Posts: 11,825
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 12:08 PM

The code I previously posted will work without specifying the width and height. But the code above works for me, having made the changes I suggested, so it is difficult for me to offer further advice. That is, other than to try different locations.
Was This Post Helpful? 1
  • +
  • -

#21 rjames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-January 14

Re: Form Attachment

Posted 25 January 2014 - 12:09 PM

Is that the only place I can change the size of the capture in the first line?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2