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