Results 1 to 4 of 4

Thread: Printing??

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2011
    Posts
    35

    Printing??

    Hi all,

    Could someone guide me with the following task I'm trying to achieve?

    I have a products table with loads of data and name of some jpg files. I want print out the entire contents along with the images. And yes, I have spent hours trying to figure the PrintDocument control, measure string, drawstring functions etc, but I'm not getting anywhere.

    The most main issue is about the new page. e.g. if I said

    while not rs.eof
    e.graphics.drawstring(somefield)
    e.graphics.drawstring(somefield1)
    e.graphics.drawstring(somefield2)
    e.graphics.drawimage(someimage)
    e.graphics.drawimage(someimage1)
    e.graphics.drawimage(someimage2)
    end while

    I'm having a few main issues

    * splitting up the field so that it's text is sent to the next line when it is longer than the margin.
    * checking the image size and resizing it to fit it inside the margin
    * and the hasmorepages. I haven't got a clue how to know what was printed last because of the fact that the contents are printing from a loop. I believe that a static variable would be useless in this case if at least the while loop was put inside the printpage handler.

    I'm almost pulling my hair for this one...

    Thanks Everybody.
    T

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

    Re: Printing??

    You don't use a loop to print multiple pages. You print one page in the PrintPage event handler, hence the name. Once you've printed a page, you set e.HasMorePages appropriately and the method completes. If e.HasMorePages was set to True then the event is raised again and you print another page. As such, you need a way to determine how much has been printed and how much is left to print at all times. You would use one or more member variables for that, which you would initialise in the BeginPrint event handler.

    Go to the VB.NET CodeBank forum and sort the threads by Thread Starter. Find Merrion's threads and read some of them. The beginner's guide to printing will give you the basics and the DataGrid printer will give you a real-world example of printing multiple pages.
    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

    Thread Starter
    Member
    Join Date
    Apr 2011
    Posts
    35

    Re: Printing??

    many thanks for a quick reply. I'm working on it and I think I'm getting somewhere..

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2011
    Posts
    35

    Re: Printing??

    just an update that I've now written a function which will perfectly print a long string by slicing it at right intervals and printing the remainder of it on following lines. if anyone wants that function, please feel free to get in touch.

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