1 / 22

Printing Support in the .NET Framework

Printing Support in the .NET Framework . The PrintDocument object Mike FITZSIMON SYSTEMS ARCHITECT F ITZSIMON IT C ONSULTING PTY LTD. Printing from .NET WHY?. Why not… print reports with Crystal Reports? or Access? automate Word? print charts from Excel?

Leo
Download Presentation

Printing Support in the .NET Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Printing Support in the .NET Framework The PrintDocument objectMikeFITZSIMONSYSTEMSARCHITECTFITZSIMON IT CONSULTING PTY LTD

  2. Printing from .NETWHY? • Why not… • print reports with Crystal Reports? • or Access? • automate Word? • print charts from Excel? • Specialist printers, eg, label / ID card printers • Print to more than one printer at once • Complex tray pulls • Graphics, CAD, Charting, GIS applications • To give your users ultimate control over report layout. FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  3. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  4. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  5. Printing Overview(all you need to know) • Create a new PrintDocument object • Set printer settings through the PrinterSettings property • Set page settings through the DefaultPageSettings property • Call the Print method to start the printing process • Handle the PrintPage event where you specify the output to print, by using the Graphics object included in the PrintPageEventArgs FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  6. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  7. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  8. Basic Printing: create a new PrintDocument object • Either drag an instance of the PrintDocument object directly from the Toolbox to the designer at design time … • or use code at run time. • Visual Basic .NETImports System.Drawing.PrintingDim myPrintDocument As _ New PrintDocument() • Visual C#using System.Drawing.Printing; PrintDocument myPrintDocument = new PrintDocument(); • Uses default settings on the default printer FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  9. Basic Printing: the PrintPage event and its handler • Call the Print method to start printingPrintDoc1.Print() • One PrintPage event is raised for each page • Handle this yourself • Use the PrintPageEventArgs.Graphics object to specify the output to printPrivate Sub PrintDoc1_PrintPage( _ ByVal sender As System.Object, _ ByVal e As PrintPageEventArgs) _ Handles PrintDoc1.PrintPage... e.Graphics.DrawString( _ "G'day World", ... e.HasMorePages = FalseEnd Sub FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  10. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  11. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  12. Print Code Demos… FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  13. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  14. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  15. PrintDemo • Printing Textppea.Graphics.DrawString("text", ... • Printing Images, logos, iconsLogoImage = _ Image.FromFile("..\FITCLogoLH.wmf")ppea.Graphics.DrawImage(LogoImage, _ ulCorner) • Printing Vector Graphics, polygons, lines, rectangles myPath.AddPolygon(... ppea.Graphics.DrawPath(Pens.Black, _ myPath) FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  16. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  17. Printer Settings • Create a new PrintDialog objectDim pdlg as NEW PrintDialog() • Associate PrintDocument object with the PrintDialogpdlg.Document = pd • Show the PrintDialog and then print with the new PrinterSettingsIf pdlg.ShowDialog() = _ DialogResult.OK Then pd.Print() FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  18. Page Setup • Create a new PageSetupDialog objectDim pdlg as NEW PageSetupDialog() • Associate PrintDocument object with the PageSetupDialog pdlg.Document = pd • Show the PageSetupDialog and then print with the new PrinterSettingsIf pdlg.ShowDialog() = _ DialogResult.OK Then ... FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  19. Run Time settings • Printer settings can be set at run time, eg,pd.PrinterSettings.PrinterName = _ "WinFax" • The PrinterSettings.InstalledPrinters property holds the list of all printers installed on the computer • Page settings can be set at run time in a PrintPage event handler, eg,ppea.Pagesettings.Landscape = True FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  20. Printing Support in the .NET Framework • Printing Overview • Basic Printing, step by step • The “G’Day World” printing program • PrintDemo, a more complex printing example • Text (fonts) • Vector Graphics (lines & splines) • Images (bitmaps, metafiles, icons) • Printer settings & Page Setup • Print Preview FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  21. Print Preview • Create a new PrintPreviewDialog objectDim pdlg as NEW _ PrintPreviewDialog() • Associate a PrintDocument object with the PrintPreviewDialog pdlg.Document = pd • Show the PrintPreviewDialog pdlg.ShowDialog() • Be prepared to execute all your PrintPage events again. FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

  22. Questions • Mike FitzsimonMike@Fitzsimon.com.au • Sample code & this ppt available fromwww.fitzsimon.com.au/qmsdnug • No trees were harmed in the presentation of this session, however… • a number of electrons were told exactly where to go. FitzsimonIT CONSULTING PTY LTD www.fitzsimon.com.au

More Related