1 Printing a Document. 2 Objectives You will be able to print a real multipage document.

Slides:



Advertisements
Similar presentations
Lesson 15: Editing, Viewing, and Printing Worksheets.
Advertisements

 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
11 User Controls II Chapter Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Chapter 7 Lists, Loops, and Printing
.NET Class 4 – Windows-based Application. WinForm Application Homogeny programming model. Rich class library Classes are shared by all.NET languages.
Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD.
Creating, Formatting, and Editing a Word Document with a Picture
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Uwe Habermann Venelina Jordanova Converting reports to Silverswitch and running VFP reports in Silverswitch.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
Basic Printing using Word. 3 Components required for printing Computer Computer Printer Printer Paper Paper.
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.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Printer & Dialog boxes Engr. Faisal ur Rehman CE-105T Spring 2007.
Word Processing ADE100- Computer Literacy Lecture 12.
Dr Dat Tran - Week 4 Lecture Notes 1 MenuStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
Chapter 7 Lists, Loops, and Printing Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
STIP Chapter#10 Mastering Windows Forms Created By, Vishwesh Patel.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes and Combo Boxes 9.2 Eight Additional Controls and Objects 9.3 Multiple-Form Programs 9.4 Graphics.
1 Scroll Bars Providing Scrollbars. 2 Objectives You will be able to: Use Windows Graphics to display tabular information on a Windows form. Add graphics.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
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.
Getting to Know InDesign
BIL528 – Bilgisayar Programlama II Introduction 1.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
1 Project 7: Northwind Traders Order Entry. 2 Northwind Order Entry Extend the Select Customer program from Project 6 to permit the user to enter orders.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Element 6 Print word processingdocuments. LEARNING OUTCOMES 1. Preview document using print preview mode. 2. Correctly select basic print options. 3.
10-1 Chapter 10 Security, Menus, Files, and Graphics.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Project 5: Printing Address Labels. 2 Assignment Write a Windows forms program to display and print a set of address labels. Input from a csv file.
The Professional Touch Programming Right from the Start with Visual Basic.NET 1/e 10.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
Printing your document is the last task you will perform before distribution. This tutorial will explain printing options. Here are some suggestions to.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Test – 2 Pre.
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
1NetBeans Tutorial Using the “Properties” menu, name the List “List1” and the button “Button1”. NetBeans Tutorial6.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
1 Windows Forms II Chapter RadioButton / GroupBox Controls Used to solicit a multiple choice input. Radio buttons work as a group. Selecting one.
1 Working with Controls at Run Time. 2 Objectives You will be able to Add controls to a Windows form at run time. Modify controls at run time.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
Printing Petzold, Chapter 21
Chapter 1: An Introduction to Visual Basic .NET
Chapter 9 Programming Based on Events
Computing with C# and the .NET Framework
Chapter 2 – Introduction to the Visual Studio .NET IDE
Visual programming Chapter 1: Introduction
Chapter 1: An Introduction to Visual Basic 2015
How to Add Images Using an 'openFile' Dialog
Self Study GUI Properties & Events
The Basic Usage and The Event Handling in Glade.
Accessing Databases with ADO.NET, Handling Exceptions, and Printing
Module 8: Creating Windows-based Applications
Chapter 13: Handling Events
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

1 Printing a Document

2 Objectives You will be able to print a real multipage document.

3 Getting Started Start with Schedule Viewer program from last class: Downloads/2011_03_22_Scroll_Bars/ Downloads/2011_03_22_Scroll_Bars/ File Schedule_Viewer_with_Scrolling.zip Enable the Print command when a file is opened. Add to openToolStripMenuItem_Click(): printToolStripMenuItem.Enabled = true;

4 State Information for Printing public partial class Form1 : Form {... // Print information int Lines_per_Page; int Next_Page; int Last_Page;

5 The Menu Double click on Print to add a command event handler.

6 Print Command Handler

7 Print Dialog Drag a PrintDocument to the form. Drag a PrintDialog to the form. Set the PrintDialog’s Document property to PrintDocument1.

8 Print Dialog

Print Command We need an event handler for a click on the Print command. In Design mode, double click on the menu command to add an event handler. Copy: Downloads/2011_03_22_Scroll_Bars/printToolStripMenuItem_Click.cs Downloads/2011_03_22_Scroll_Bars/printToolStripMenuItem_Click.cs 9

10 Print Command Handler private void printToolStripMenuItem_Click( object sender, EventArgs e) { Lines_per_Page = 15; // Force multiple pages int Number_of_Pages = Schedule.Count / Lines_per_Page; if (Schedule.Count % Lines_per_Page > 0) { Number_of_Pages++; } printDialog1.AllowSelection = false; printDialog1.AllowSomePages = true; printDialog1.PrinterSettings.MinimumPage = 1; printDialog1.PrinterSettings.MaximumPage = Number_of_Pages; printDialog1.PrinterSettings.FromPage = 1; printDialog1.PrinterSettings.ToPage = Number_of_Pages;

11 Print Command Handler if (printDialog1.ShowDialog() == DialogResult.OK) { Next_Page = printDialog1.PrinterSettings.FromPage; Last_Page = printDialog1.PrinterSettings.ToPage; printDocument1.Print(); }

12 Add PrintPage Event Handler Double click on printDocument1. Visual Studio adds a skeleton PrintPage event handler. private void printDocument1_PrintPage( object sender, System.Drawing.Printing.PrintPageEventArgs e) { } Fill in the event handler. Downloads/2011_03_22_Scroll_Bars/printDocument1_PrintPage.cs Downloads/2011_03_22_Scroll_Bars/printDocument1_PrintPage.cs

PrintPage Event Handler private void printDocument1_PrintPage( object sender, System.Drawing.Printing.PrintPageEventArgs e) { int Print_Y_Pos = e.MarginBounds.Top; int First_Output_Line = (Next_Page - 1) * Lines_per_Page; int Last_Output_Line = First_Output_Line + Lines_per_Page - 1; if (Last_Output_Line >= Schedule.Count) { Last_Output_Line = Schedule.Count - 1; } for (int i = First_Output_Line; i <= Last_Output_Line; i++) { Point P = new Point(e.MarginBounds.Left, Print_Y_Pos); Schedule_Record se = Schedule[i]; se.Output(e.Graphics, Font1, Brush1, P); Print_Y_Pos += Font1.Height; } Next_Page++; e.HasMorePages = (Next_Page <= Last_Page); }

14 Printing a Schedule Entry The actual output to the printer is done by the same Schedule_Record method that draws a schedule entry on the screen. Schedule_Record.Output The Graphics object for output to the printer comes from the PrintPageEventArgs parameter of the PrintPage event handler.

15 Build and Test Should print three pages.

16 The PrintPreview Dialog Let’s add a Print Preview Dialog. Permit the user to view what would be printed on the screen.

17 PrintPreview Dialog The PrintPreview dialog handles multiple pages automatically You must provide the code to print multiple pages in your handler for the PagePrint event. Also handles Zoom View multiple pages Print No additional effort on your part! But be sure any initialization done for the print command is also done for print preview.

18 Add Print Preview Command Double click on Print Preview to create event handler.

19 Add Print Preview Command Enable Print Preview command when file is opened. private void openToolStripMenuItem_Click(object sender, EventArgs e) { import_schedule();... openToolStripMenuItem.Enabled = false; printToolStripMenuItem.Enabled = true; printPreviewToolStripMenuItem.Enabled = true; }

20 The PrintPreview Command Handler private void printPreviewToolStripMenuItem_Click( object sender, EventArgs e) { Initialize_Printing(); if (printDialog1.ShowDialog() == DialogResult.OK) { Next_Page = printDialog1.PrinterSettings.FromPage; Last_Page = printDialog1.PrinterSettings.ToPage; PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = printDocument1; ppd.ShowDialog(); }

21 The PrintPreview Command Handler Add function Initialize_Printing() Move initialization code from Print command handler. Same initialization for Print and PrintPreview.

22 Initialize_Printing() private void Initialize_Printing() { Lines_per_Page = 15; // Force multiple pages Number_of_Pages = Schedule.Count / Lines_per_Page; if (Schedule.Count % Lines_per_Page > 0) { Number_of_Pages++; } printDialog1.AllowSelection = false; printDialog1.AllowSomePages = true; printDialog1.PrinterSettings.MinimumPage = 1; printDialog1.PrinterSettings.MaximumPage = Number_of_Pages; printDialog1.PrinterSettings.FromPage = 1; printDialog1.PrinterSettings.ToPage = Number_of_Pages; }

23 Revised Print Command Handler private void printToolStripMenuItem_Click( object sender, EventArgs e) { Initialize_Printing(); if (printDialog1.ShowDialog() == DialogResult.OK) { Next_Page = printDialog1.PrinterSettings.FromPage; printDocument1.Print(); }

24 PrintPreview Dialog