Results 1 to 9 of 9

Thread: [RESOLVED] Second thread help needed - mail issue

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Resolved [RESOLVED] Second thread help needed - mail issue

    Hello again

    I know how to send mail and define the email body. Here's my issue:

    I have a form with checkboxes and textfields which I want to print out. Is there any easy way to go about this?

    I was thinking about transfering the information entered into a text file and print it out, but that just seems too stupid.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Second thread help needed - mail issue

    What does the printing have to do with the e-mail?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Second thread help needed - mail issue

    So are these just strings of text?? If so, check out a .NET printing class

    If you wish to just print an image of the form, check out my sig for the "Easy Screen Capture Class" in order to get a snapshot of the form by its handle....

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: Second thread help needed - mail issue

    I mean printing... But I also have to send the form info to email. I forgot to say. Sorry

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: Second thread help needed - mail issue

    Quote Originally Posted by gigemboy
    So are these just strings of text?? If so, check out a .NET printing class

    If you wish to just print an image of the form, check out my sig for the "Easy Screen Capture Class" in order to get a snapshot of the form by its handle....
    I will try this special class. Thank you.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: Second thread help needed - mail issue

    Last thing thoug. The window img grabber works fine. Anybody know how to print directly from memory? This would be preferable so that I won't be messing with the clients harddrive.

    And also. The printdocument class makes no sense to me.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Second thread help needed - mail issue

    Actually, the PrintDocument class and it's use are really quite simple, but widely misunderstood because they don't work how people expect printing to work.

    1. You create a PrintDocument object.
    2. You call its Print method.
    3. You handle its PrintPage event and use GDI+ to print exactly what you want, exactly where you want.

    The reason people get confused is that they don't know how to use GDI+ properly. It may seem like a lot of trouble to calculate exactly where on a page something has to be printed, what font to use and so on, but this method gives you absolute control over every aspect of your printing, so it's very powerful. Here's a quick example that will print three lines, one to a page, displaying the current page number:
    VB Code:
    1. Private pageNumber As Integer 'The number of the page being printed.
    2.  
    3.     Private Sub Print()
    4.         Dim pd As New Printing.PrintDocument()
    5.  
    6.         AddHandler pd.PrintPage, AddressOf PrintPage
    7.  
    8.         'Set the initial page number.
    9.         Me.pageNumber = 1
    10.  
    11.         'Start printing.
    12.         pd.Print()
    13.     End Sub
    14.  
    15.     Private Sub PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
    16.         Dim stringToPrint As String = String.Format("This is page {0}", Me.pageNumber)
    17.         Dim printFont As New Font(FontFamily.GenericSansSerif, 12)
    18.         Dim xLocation As Integer = 25
    19.         Dim yLocation As Integer = 25 + (Me.pageNumber - 1) * 50
    20.  
    21.         'Draw the string on the printing surface.
    22.         e.Graphics.DrawString(stringToPrint, printFont, Brushes.Black, xLocation, yLocation)
    23.  
    24.         If Me.pageNumber < 3 Then
    25.             'Print more pages.
    26.             Me.pageNumber += 1
    27.             e.HasMorePages = True
    28.         Else
    29.             'All pages have been printed.
    30.             e.HasMorePages = False
    31.         End If
    32.     End Sub
    Note that if you set e.HasMorePages to True the PrintPage event will be raised again and you can print another page. This means that you need some way to keep track of where you are up to in the printing process. In this case I have used the class level variable named pageNumber. In a more complex scenario you may need to track more information between events. I've used the DrawString method to simply print a single string at a different location depending on the page. The Graphics object can draw strings, images and many different shapes, thus giving you an enormous range of things you can print.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Second thread help needed - mail issue

    The capture class does capture in memory (since you said it worked fine)... there are ways to just grab the image in an image object (CaptureWindow method), then you just use the graphics object to draw the image to print...

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: Second thread help needed - mail issue

    Thanks guys... Hopefully I can figure it out. I will something with the above code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width