STIP Chapter#10 Mastering Windows Forms Created By, Vishwesh Patel.

Slides:



Advertisements
Similar presentations
Copyright 2003 Peter McDevitt 1 Microsoft Excel 2002 Lecture 3 – A Professional Looking Worksheet.
Advertisements

Foundation Level Course
Microsoft ® Word 2010 Core Skills Lesson 5: Formatting Documents Courseware #: 3240 Microsoft Office Word 2010.
Microsoft Office 2007: Introductory Computer Applications 11.
Automating Tasks With Macros
Creating Custom Forms. 2 Design and create a custom form You can create a custom form by modifying an existing form or creating a new form. Either way,
Advanced Object-Oriented Programming Features
Using Templates Object-Oriented Programming Using C++ Second Edition 11.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 13: Object-Oriented Programming
Chapter 14: Event-Driven Programming with Graphical User Interfaces
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
A+ Guide to Software, 4e Chapter 11 Supporting Printers and Scanners.
Microsoft ® Office Word 2007 Training Mail Merge II: Use the Ribbon and perform a complex mail merge [Your company name] presents:
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
© 2002 ComputerPREP, Inc. All rights reserved. Word 2000: Working with Long Documents.
Create Professional-looking Content Easy to Use Interface Share Documents.
A First Program Using C#
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 6 Configuring Windows Server 2008 Printing
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
IE 411/511: Visual Programming for Industrial Applications
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
ICONICS ActiveX ToolWorX V 6.1.
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Windows Programming Using C# Printing, Documentation, & Deployment.
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 11 Organizing the Worksheet.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
Desktop Publishing Formatting Pages. Topics to Study Page Setup Apply Built-in options Use Layout Guides Color- Coded Guides Insert Page numbers Create.
Formatting WorksheetsFormatting Worksheets Lesson 7.
Chapter 4 Introduction to Classes, Objects, Methods and strings
1 CA201 Word Application Arranging and Printing Documents Week # 4 By Tariq Ibn Aziz Dammam Community college.
1 Using Templates COSC 1567 C++ Programming Lecture 10.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
Unit 1: Plotting DT2510: Advanced CAD Methods. Identifying the user interface: Application menu Quick Access toolbar InfoCenter Ribbon Drawing window.
Chapter 15: Customizing Forms. ©The McGraw-Hill Companies, Inc. 2 of 36 Customizing Forms Chapter 15 starts Part 4 of the book: Advanced Peachtree Complete.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 9 Creating a Reference Document with a Table of Contents and an Index Microsoft Word 2013.
Introduction to Object-Oriented Programming Lesson 2.
Ⅰ. PS Driver ML-4050N Series PostScript, Driver ML-4050N Series PostScript, Driver.
Word Create a basic TOC. Course contents Overview: table of contents basics Lesson 1: About tables of contents Lesson 2: Format your table of contents.
Microsoft PowerPoint 2013 Lesson 2.02 – Presentation Basics.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
Laboratory Exercise # 10 – Microsoft Word Additional Topics Office Productivity Tools 1 Laboratory Exercise # 10 Microsoft Word Additional Topics Objectives:
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
MS WORD INFORMATION TECHNOLOGY MANAGEMENT SERVICE Training & Research Division.
Desktop Publishing Lesson 3 — Formatting Pages. Lesson 3 – Formatting Pages2 Objectives  Set up pages.  Set guides.  Use master pages.  Insert page.
Change margins. 1 Preview a document. 2 Change paper size and orientation. 3 Print envelopes and labels. 4 Choose print options. 5 2.
6. (supplemental) User Interface Design. User Interface Design System users often judge a system by its interface rather than its functionality A poorly.
Lecture 8: Collections, Comparisons and Conversions. Svetla Boytcheva AUBG, Spring COS 240 Object-Oriented Languages.
Modifying Page Layout You may find that the default page layout settings in Word are not sufficient for the document you want to create, in which case.
© 2004 The McGraw-Hill Companies, Inc. All rights reserved. The Advantage Series Microsoft Office Word 2003 CHAPTER 4 Printing and Web Publishing.
Printing Petzold, Chapter 21
Microsoft Foundation Classes MFC
The Pseudocode Programming Process
Microsoft Office Access 2003
Microsoft Office Access 2003
Programming with Microsoft Visual Basic 2008 Fourth Edition
Accessing Databases with ADO.NET, Handling Exceptions, and Printing
HIBBs is a program of the Global Health Informatics Partnership Learning the Basics of Microsoft Word 2019 and Microsoft office support TFN
C++ Object Oriented 1.
Presentation transcript:

STIP Chapter#10 Mastering Windows Forms Created By, Vishwesh Patel

Mastering Windows Forms Printing Printing is an integral part of every complete Windows-based application Now, printing from Windows Forms with the.NET Framework means you must adopt a document-centric approach, resulting in cleaner and more manageable code While the System.Windows.Forms namespace provides seamless integration with all the standard print dialogs (such as Print Preview, Page Setup, and Print), The System.Drawing.Printing namespace offers numerous classes for extensibility and customization

Mastering Windows Forms These classes, and how they provide access to printing capabilities, are covered here. Other useful techniques, such as printing in the background to allow the user to continue other tasks, is also explained. you carefully keep track of the printing process using the Win32® API, to ensure that pages are printed correctly This sample Windows Forms application, shown in Figure 1, demonstrates many of the new features and capabilities you'll have access to when printing in.NET.

Mastering Windows Forms It allows you to choose any text document and send it to either the Print Preview dialog or to a specific printer. For demonstration purposes, I'll give you an option for selecting whether a watermark should be displayed on each page. When printing using the Print Preview dialog, you can enable or disable anti-aliasing, a built-in feature that renders text and graphics on the screen with a smoother appearance. Keep in mind, however, that this incurs the cost of reduced output speed.

Mastering Windows Forms

Let's take a tour of Windows Forms printing by first examining the quick and dirty way to send output to the printer. I will then look more closely at the right way to print from Windows Forms—using a derived PrintDocument class Using the Print Document class Printing from Windows Forms is a document- centric, event-driven process. The bulk of your effort will go into either using a generic PrintDocument object or implementing a derived PrintDocument class

Mastering Windows Forms Printing with a base PrintDocument class requires you to wire the class's PrintPage event to a handler method (static or instance) whose signature matches the PrintPageEventHandler delegate This event will fire when your code calls the Print method on an instance of a PrintDocument object The Graphics property of the PrintPageEventArgs object exposes a GDI+ object that encapsulates the drawing surface onto which you paint your page.

Mastering Windows Forms To print more than one page, you notify the underlying print controller that you have more to print. You can do this using the HasMorePages property of the PrintPageEventArgs object. Setting the HasMorePages property to true will ensure that your PrintPage event handler gets called again.

Mastering Windows Forms In addition, you can set up event handlers for other common print events such as BeginPrint, EndPrint, and QueryPageSettings. BeginPrint is a good place to initialize any objects (such as Fonts) that your PrintPage routine may rely on. The QueryPageSettings event fires immediately before each PrintPage event Here's an example that illustrates how to initiate a print job using the base PrintDocument class:

Mastering Windows Forms

Implementing a Derived PrintDocument Class When printing from Windows Forms, a better approach is to implement a class that inherits from the generic PrintDocument class. Doing so, you'll quickly reap the rewards of encapsulation. Instead of implementing event handlers for the BeginPrint, EndPrint, and PrintPage events, you override the OnBeginPrint, OnEndPrint, and OnPrintPage methods of the underlying PrintDocument base class

Mastering Windows Forms The sample printing application uses a derived PrintDocument class of type TextPrintDocument, as shown in Figure 2. The TextPrintDocument class exposes an overloaded constructor that takes a file name as an argument Alternatively, the file name can be set and read using a custom FileToPrint property. This property throws an exception when set to a nonexistent file. This class also exposes a public Boolean field, named Watermark, which enables or disables a page background graphic

Mastering Windows Forms

Printing: How default printing is done In MFC applications, the view class has a member function named OnDraw that contains all the drawing code. OnDraw takes a pointer to a object as a parameter. That CDC object represents the device context to receive the image produced by OnDraw

Mastering Windows Forms In programming for Windows, sending output to the printer is very similar to sending output to the screen. This is because the Windows graphics device interface (GDI) is hardware-independent. You can use the same GDI functions for screen display or for printing simply by using the appropriate device context. If the CDC (Change data capture) object that OnDraw receives represents the printer, OnDraw’s output goes to the printer

Mastering Windows Forms This explains how MFC applications can perform simple printing without requiring extra effort on your part. The framework takes care of displaying the Print dialog box and creating a device context for the printer. When the user selects the Print command from the File menu, the view passes this device context to OnDraw, which draws the document on the printer

Mastering Windows Forms There are significant differences between printing and screen display When you print, you have to divide the document into distinct pages and display them one at a time, rather than display whatever portion is visible in a window. As a corollary, you have to be aware of the size of the paper (whether it’s letter size, legal size, or an envelope). You may want to print in different orientations, such as landscape or portrait mode. The Microsoft Foundation Class Library can’t predict how your application will handle these issues, so it provides a protocol for you to add these capabilities in Multipage document.

Mastering Windows Forms Multipage Documents describes the Windows printing protocol and explains how to print documents that contain more than one page. The article covers the following topics: Printing protocol Overriding view class functions Pagination Printer pages vs. document pages Print-time pagination

Mastering Windows Forms The Printing Protocol To print a multipage document, the framework and view interact in the following manner. First the framework displays the Print dialog box, creates a device context for the printer, and calls the member function of the object. Then, for each page of the document, the framework calls the member function of the CDC object, instructs the view object to print the page, and calls the member function. (repeat mode) If the printer mode must be changed before starting a particular page, the view object sends the appropriate escape code by calling the member function of the CDC object. When the entire document has been printed, the framework calls the member function.

Mastering Windows Forms Overriding View Class Functions The class defines several member functions that are called by the framework during printing. By overriding these functions in your view class, you provide the connections between the framework’s printing logic and your view class’s printing logic. The following table lists these member functions.

Mastering Windows Forms CView’s Overridable Functions for Printing You can do printing-related processing in other functions as well, but these functions are the ones that drive the printing process

Mastering Windows Forms The following figure illustrates the steps involved in the printing process and shows where each of CView’s printing member functions are called. Additional parts of the printing process are described in the article Printing: Allocating GDI Resources.Printing: Allocating GDI Resources

Mastering Windows Forms Printing Loop

Mastering Windows Forms Pagination The framework stores much of the information about a print job in a structure. Several of the values in CPrintInfo pertain to pagination; these values are accessible as shown in the following table.

Mastering Windows Forms Page Number Information Stored in CPrintInfo table:

Mastering Windows Forms Printing: Allocating GDI Resources explains how to allocate and deallocate the Windows graphics device interface (GDI) objects needed for printing. Suppose you need to use certain fonts, pens, or other GDI objects for printing, but not for screen display. Because of the memory they require, it’s inefficient to allocate these objects when the application starts up. When the application isn’t printing a document, that memory might be needed for other purposes. It’s better to allocate them when printing begins, and then delete them when printing ends.

Mastering Windows Forms To allocate these GDI objects, override the member function. This function is well suited to this purpose for two reasons: the framework calls this function once at the beginning of each print job and, unlike, this function has access to the object representing the printer device driver. You can store these objects for use during the print job by defining member variables in your view class that point to GDI objects

Mastering Windows Forms To use the GDI objects you’ve created, select them into the printer device context in the member function. If you need different GDI objects for different pages of the document, you can examine the m_nCurPage member of the structure and select the GDI object accordingly. If you need a GDI object for several consecutive pages, Windows requires that you select it into the device context each time OnPrint is called. To deallocate these GDI objects, override the member function. The framework calls this function at the end of each print job, giving you the opportunity to deallocate printing- specific GDI objects before the application returns to other tasks

Mastering Windows Forms One way to compensate for the area taken by the header or footer is to use the m_rectDraw member of. Each time a page is printed, this member is initialized with the usable area of the page. If you print a header or footer before printing the body of the page, you can reduce the size of the rectangle stored in m_rectDraw to account for the area taken by the header or footer. Then OnPrint can refer to m_rectDraw to find out how much area remains for printing the body of the page

Mastering Windows Forms You cannot print a header, or anything else, from, because it is called before the StartPage member function of has been called. At that point, the printer device context is considered to be at a page boundary. You can perform printing only from the OnPrint member function