View
216
Download
1
Tags:
Embed Size (px)
Citation preview
Printing Support in the .NET Framework
The PrintDocument object MikeFITZSIMONSYSTEMSARCHITECT
FITZSIMON IT CONSULTING PTY LTD
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
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.
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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.PrintingDim myPrintDocument As _ New PrintDocument()
Visual C#
using System.Drawing.Printing; PrintDocument myPrintDocument = new PrintDocument();
Uses default settings on the default printer
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
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 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 = FalseEnd Sub
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
Print Code Demos…
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
PrintDemo
Printing Text ppea.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)
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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 PrinterSettingsIf pdlg.ShowDialog() = _ DialogResult.OK Then pd.Print()
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
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 ...
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING 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
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
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.
Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au
Questions
Mike [email protected]
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.