Presentation is loading. Please wait.

Presentation is loading. Please wait.

Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD.

Similar presentations


Presentation on theme: "Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD."— Presentation transcript:

1 Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

2 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Printing from.NET WHY? 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.

3 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

4 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

5 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

6 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

7 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

8 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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.NET Imports System.Drawing.Printing Dim myPrintDocument As _ New PrintDocument() Visual C# using System.Drawing.Printing; PrintDocument myPrintDocument = new PrintDocument(); Uses default settings on the default printer

9 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Basic Printing: the PrintPage event and its handler Call the Print method to start printing PrintDoc1.Print() One PrintPage event is raised for each page Handle this yourself Use the PrintPageEventArgs.Graphics object to specify the output to print Private Sub PrintDoc1_PrintPage( _ ByVal sender As System.Object, _ ByVal e As PrintPageEventArgs) _ Handles PrintDoc1.PrintPage... e.Graphics.DrawString( _ "G'day World",... e.HasMorePages = False End Sub

10 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

11 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

12 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Print Code Demos…

13 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

14 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

15 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au PrintDemo Printing Text ppea.Graphics.DrawString("text",... Printing Images, logos, icons LogoImage = _ Image.FromFile("..\FITCLogoLH.wmf") ppea.Graphics.DrawImage(LogoImage, _ ulCorner) Printing Vector Graphics, polygons, lines, rectangles myPath.AddPolygon(... ppea.Graphics.DrawPath(Pens.Black, _ myPath)

16 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

17 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Printer Settings Create a new PrintDialog object Dim pdlg as NEW PrintDialog() Associate PrintDocument object with the PrintDialog pdlg.Document = pd Show the PrintDialog and then print with the new PrinterSettings If pdlg.ShowDialog() = _ DialogResult.OK Then pd.Print()

18 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Page Setup Create a new PageSetupDialog object Dim pdlg as NEW PageSetupDialog() Associate PrintDocument object with the PageSetupDialog pdlg.Document = pd Show the PageSetupDialog and then print with the new PrinterSettings If pdlg.ShowDialog() = _ DialogResult.OK Then...

19 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

20 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au 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

21 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Print Preview Create a new PrintPreviewDialog object Dim 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.

22 Fitzsimon IT C ONSULTING PTY LTD www.fitzsimon.com.au Questions Mike Fitzsimon Mike@Fitzsimon.com.au Sample code & this ppt available from www.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.


Download ppt "Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD."

Similar presentations


Ads by Google