Results 1 to 4 of 4

Thread: [2005] How to print Bitmap object

  1. #1

    Thread Starter
    Hyperactive Member jonwondering's Avatar
    Join Date
    May 2005
    Posts
    311

    [2005] How to print Bitmap object

    It's been years since I've printed in VB 6, and I have no idea how to do it in .net. I have a bitmap object and a line of text. How would I print that?

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

    Re: [2005] How to print Bitmap object

    Printing is always done exactly the same way in .NET regardless of what you want to print. You create a PrintDocument object, which you can add to a form in the designer, and call its Print method. You then handle its PrintPage event to print a page. In the PrintPage event handler you are provided a Graphics object via the e.Graphics property. You use this to draw via GDI+, exactly the same way as you would draw on a control. In your case you need to call its DrawImage and DrawString methods. The 2003 101 Samples contains a printing sample. Perhaps the 2005 101 Samples do too but if not the 2003 version will work in 2005. The example probably only prints text but if you want to print anything else it's still exactly the same except you substitute the appropriate method for DrawString.
    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
    Hyperactive Member jonwondering's Avatar
    Join Date
    May 2005
    Posts
    311

    Re: [2005] How to print Bitmap object

    thanks jmcilhinney! i couldn't find many examples on the internet about printing, guess not many are that interested in printing these days...

    Edit: btw you wouldn't know how to twist the page sideways, would you? I can't figure it out...
    Last edited by jonwondering; Jul 31st, 2006 at 08:53 AM.

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

    Re: [2005] How to print Bitmap object

    If you mean print in landscape rather than portrait then you make it the default for all pages like this:
    VB Code:
    1. Me.PrintDocument1.DefaultPageSettings.Landscape = True
    or set it for an individual page like this:
    VB Code:
    1. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
    2.                                      ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    3.     e.PageSettings.Landscape = True
    4.  
    5.     'Print the page here.
    6. End Sub
    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