Results 1 to 4 of 4

Thread: [2005] Printing a listbox content

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    4

    [2005] Printing a listbox content

    Ok, this is a simple thing which I can't find how to do. Situation:
    I have a listbox that has a stock list in it. I want to print out the listbox onto paper for use as a hard copy. How can I print things out in VB2005, and especially how to do it from a listbox?

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

    Re: [2005] Printing a listbox content

    Forget the ListBox for the moment and work out the generalities of printing. You should start by reading up on the PrintDocument class, which is the heart of .NET printing. There is information in the documentation and tons of examples on this site and elsewhere on the Web. Once you understand how to print a page of text, then it's time to consider specialising the process to your circumstances.
    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
    New Member
    Join Date
    Mar 2008
    Posts
    4

    Re: [2005] Printing a listbox content

    As much as that helps me, I only have 2 years of programming with me. And thats limited to VB and Prolog. Ive read up about the print class but its not making much sense to me. If anybody could help me out it would be helpful. I would normally just read up on it but I gotta get this working in a week.

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

    Re: [2005] Printing a listbox content

    Create a PrintDocument object, most likely by adding it to the form in the designer. Call its Print method and handle its PrintPage event to print a page. Use GDI+, through the e.Graphics property, to draw onto the print surface. To draw text you call the DrawString method.

    If you want to print the contents of a ListBox then you need to loop through its Items and call DrawString for each one, changing the Y component of the location each time. Note that if there are a large number of items then you may need to print more than one page.
    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

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