Raise Printing to a Fine Art in Windows Forms

Raise Printing to a Fine Art in Windows Forms - Raise...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Raise Printing to a Fine Art in Windows Forms http://www.devx.com/dotnet/Article/31527/1954?pf=true 1 of 8 11/22/2006 10:19 AM http://www.devx.com Printed from http://www.devx.com/dotnet/Article/31527 Raise Printing to a Fine Art in Windows Forms Learn how to format, preview, and print output the way you want it to look using the capabilities of the .NET System.Drawing.Printing namespace and the PrintDocument class. by Wei-Meng Lee rinting is an integral functionality found in almost every decent Windows application. For example, you might be working on a POS (Point of Sale) application and need to print receipts, or you may want to print out employee records from a database. In either case, you need to be able to send the output directly to the printer. What's more, you must have the capability to format the printout the way you want it to appear on paper. Fortunately, the System.Drawing.Printing namespace in .NET contains all the necessary classes for printing-related services. Specifically, using the PrintDocument class, you can now print from your Windows-based application with ease. In this article, I will show you how to print from your Windows-based .NET applications. To do so, I'll build a sample application that prints employee name cards using data from the SQL Server Northwind sample database. If you do not already have access to the Northwind database in your environment, you can install it from the freely downloadable SQL Server 2005 Express edition or you can download the Northwind and pubs sample databases for SQL Server 2000 . Author's Note: The printing logic described here should work in VS.NET 2003; but the drag-and-drop data-binding shown requires VS 2005. Creating the Application Using Visual Studio 2005, create a new Windows application and name the project C:\Printing. You will use the data-binding feature in Windows Forms 2.0 to display records from the Employees table in Northwind. First, add a data source to the project by selecting Data—>Add New Data Source…. The Data Source Configuration Wizard will appear. Select Database, and click Next. Click the "New Connection…" button to create a connection to the SQL Server 2005 Express database server (henceforth referred to as SQL Express). In the Add Connection window, enter ".\SQLEXPRESS" as the server name (this refers to the SQL Express database server installed on the current computer). Then, select the Northwind database (see Figure 1 ). Click OK.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Raise Printing to a Fine Art in Windows Forms http://www.devx.com/dotnet/Article/31527/1954?pf=true 2 of 8 11/22/2006 10:19 AM Figure 1 . Connecting to Northwind: The sample application uses the Northwind sample database. Figure 2 . Picking Your Data: Select the fields (as indicated) from the Employees table. Back in the Data Source Configuration Wizard, click Next. In the "Choose Your Database Objects" window,
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/16/2008 for the course MIS 225 taught by Professor Byrtus during the Winter '08 term at Mercyhurst.

Page1 / 8

Raise Printing to a Fine Art in Windows Forms - Raise...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online