Form Attachment

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 rjames  Icon User is offline

  • New D.I.C Head

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

Form Attachment

Posted 24 January 2014 - 12:01 PM

I have created an e-mail function for a program I'm writing so that I can send a form as an attachment. Yet I can't find a way to do this. I was thinking of using the FileDialog component so that I can select it from the vb folder then storing it in a variable and using that as reference to the attachment part of my code. However the form doesn't display properly. :/

Can anyone help me?

Is This A Good Question/Topic? 0
  • +

Replies To: Form Attachment

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: Form Attachment

Posted 24 January 2014 - 02:21 PM

Do you mean take a screen shot of the form? If not, then please explain it better.
Was This Post Helpful? 0
  • +
  • -

#3 rjames  Icon User is offline

  • New D.I.C Head

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

Re: Form Attachment

Posted 24 January 2014 - 03:43 PM

I mean literally taking a form as a individual file, that's readable to those without visual basic, and sending it as an attachment through a SMTP server :)
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: Form Attachment

Posted 24 January 2014 - 05:42 PM

What part are you hung up on? What code have you tried?
Was This Post Helpful? 0
  • +
  • -

#5 rjames  Icon User is offline

  • New D.I.C Head

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

Re: Form Attachment

Posted 24 January 2014 - 05:44 PM

View Post_HAWK_, on 24 January 2014 - 05:42 PM, said:

What part are you hung up on? What code have you tried?


Im new to VB and couldnt quite find a way to begin with:/
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Re: Form Attachment

Posted 24 January 2014 - 07:02 PM

You cannot just send the form's file. You need to save a representation of form as a sensible file-type, typically an image.

This code from SO:
Private Sub capture(ctrl As Control, fileName As String)
    Dim bounds As Rectangle = ctrl.Bounds
    Dim pt As Point = ctrl.PointToScreen(bounds.Location)
    Dim bitmap As New Bitmap(bounds.Width, bounds.Height)
    Using g As Graphics = Graphics.FromImage(bitmap)
        g.CopyFromScreen(New Point(pt.X - ctrl.Location.X, pt.Y - ctrl.Location.Y), Point.Empty, bounds.Size)
    End Using

    bitmap.Save(fileName, ImageFormat.Png)
End Sub

saves an image of a Control, but the Control could be the form itself.

It would be possible to take a screenshot of the active window, but you would still (I believe) need to convert it to an image before sending it. (This is pretty much what the above code does anyway.)

It would also be possible to create a pdf from the form but this sounds like a lot of work to me :whatsthat:/>
Was This Post Helpful? 0
  • +
  • -

#7 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 - 04:24 AM

From getting the image how would I use filedialog to attach it along with the email?

This post has been edited by andrewsw: 25 January 2014 - 05:44 AM
Reason for edit:: removed previous quote

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 05:46 AM

Why would you need the FileDialog?
Was This Post Helpful? 0
  • +
  • -

#9 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 - 07:51 AM

View Postandrewsw, on 25 January 2014 - 05:46 AM, said:

Why would you need the FileDialog?

I can use it to search for the image's saved location then select it as an attachment onto the email can't I?
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 07:57 AM

If you will be adopting the code I posted above then, having saved the image, you would already know the image's location.
Was This Post Helpful? 0
  • +
  • -

#11 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 - 08:01 AM

View Postandrewsw, on 25 January 2014 - 07:57 AM, said:

If you will be adopting the code I posted above then, having saved the image, you would already know the image's location.


If that's the case, the image being saved on a separate form from the e-mail form if you get me?
Your code - done on another form
It needs to get to the next form which is the e-mail form, I don't understand how I can actually send the image with the email as an attachment.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 08:30 AM

I have a tutorial on Passing Data Between Forms. You could perhaps pass the image location to the second form as an argument to a constructor.

Quote

I don't understand how I can actually send the image with the email as an attachment.

You said that you have created an email function for your program already. If so, then adding an attachment isn't much more difficult. You will need to describe what you have tried and, specifically, what you are struggling with.

Please note that there is no need to keep quoting the previous reply, there is a larger Reply button a little further down the page.
Was This Post Helpful? 0
  • +
  • -

#13 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 - 08:38 AM

Sorry about that Im away from my desktop and using my phone. I have tried using the filedialogopen component but I tried to use the vb form inside the project folder this obviously didnt work which I sort of already knew but did just in case. Besides this I would use the code provided to get the image. Id then pass it like you mentioned to the next form which is the email form. My exact problem is I wouldnt know how to attach the image once its passed to the email that is going to be sent.
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Re: Form Attachment

Posted 25 January 2014 - 08:44 AM

Quote

My exact problem is I wouldnt know how to attach the image once its passed to the email that is going to be sent.

As I have said, you need to explain what you have tried. As you don't know how, then you need to find this out: do some research, try something.
Was This Post Helpful? 0
  • +
  • -

#15 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:02 AM

The code above that you shared with me, how is it actually used before I go ahead and fail to understand?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2