© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.

Slides:



Advertisements
Similar presentations
Microsoft Word – Lesson 1
Advertisements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
PowerPoint. Getting Started with PowerPoint Objectives Start PowerPoint and open presentations Explore toolbars and menus Use the Office Assistant Work.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Lynn Hogan, Amy Rutledge, Cyndi Krebs, Eric.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Painter Application Introducing Graphics with Windows Presentation Foundation.
® Microsoft Office 2010 Word Tutorial 1 Creating a Document.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
McGraw-Hill Technology Education © 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Office Word 2003 Lab 3 Creating Reports and Tables.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Microsoft Office 2003 Illustrated Brief Document Enhancing a.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
A First Program Using C#
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introducing Web Controls Outline 29.1 Analyzing the.
Chapter 7 Lists, Loops, and Printing Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Graphics and Multimedia Part #2
BIM211 – Visual Programming Objects, Collections, and Events 1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
Macromedia Studio 8 Step-by-Step MACROMEDIA FIREWORKS 8 Project 2: Experience Bank Logo.
TUTORIAL 5 INSTRUCTOR: HANIF ULLAH ID: OFFICE #: 2029 DATE: 18/11/2012 Introduction to MS Project 2007.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 3.1 Test-Driving the Welcome Application 3.2.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Microsoft ® Office 2007 PowerPoint Lecture to Accompany.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Chapter 4 Introduction to Classes, Objects, Methods and strings
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 15 – Fund Raiser Application Introducing.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Office 2010 Vol. 1, 2e PowerPoint Lecture to Accompany.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application: Client Tier Introducing Web Controls.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Office 2010 Vol. 1, 2e PowerPoint Lecture to Accompany.
DAY 25: WORD CHAPTER Rohit March 28,
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Office 2010 Vol. 1, 2e PowerPoint Lecture to Accompany.
Graphics and Multimedia
CASE Tools Graphical User Interface Programming Using C#
Repetition and Multiple Forms
Skills for Success with Microsoft® Office 2010
Presentation transcript:

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics and Printing Outline 26.1Test-Driving the CheckWriter Application 26.2GDI+ Introduction 26.3Constructing the CheckWriter Application 26.4 PrintPreviewDialog s and PrintDocument s 26.5Creating an Event Handler for the CheckWriter Application 26.6 Graphics Objects: Colors, Lines and Shapes 26.7Printing Each Control of the CheckWriter Application 26.8 Font Class 26.9Previewing and Printing the Check 26.10Wrap-Up 1

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Objectives In this tutorial, you will learn to: –Draw two-dimensional shapes. –Control the colors and patterns of filled shapes. –Use Graphics objects. –Draw shapes on an object. –Create an application to write checks. 2

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Introduction API : interface used by a program to access the operating system and various services on the computer GDI+: graphics API that provides classes for creating and manipulating two-dimensional vector graphics, fonts, and images Vector graphic : not represented by a grid of pixels, but by a set of mathematical properties called vectors, which describe a graphic’s dimensions, attributes, and position 3

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.1Test-Driving the CheckWriter Application 4

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.1Test-Driving the CheckWriter Application Figure 26.1 CheckWriter application displaying an empty check. Company information Written check amount Memo text Check numberDateAmountRecipient 5

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.1Test-Driving the CheckWriter Application Figure 26.2 CheckWriter application displaying a completed check. Where MICR numbers are located on a check 6 Magnetic Ink Character Recognition (MICR) numbers – Bank’s routing number (9 digits), followed by account number and check number. – Special machines read MICR number and route check to appropriate account

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.1Test-Driving the CheckWriter Application Figure 26.3 Preview of the completed check. Page to view Close Print Zoom Displays three pages 7

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.2GDI+ Introduction Pen : used to draw lines in various styles Brush: used to fill a shape (solid color or pattern) Color : contains pre-defined colors and allows you to create custom colors Font : contains font properties like Bold, Italic, and Size –FontFamily : contains methods for obtaining font information Coordinate System: used to identify all points on the screen – x-coordinate: horizontal position – y-coordinate: vertical position 8

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.2GDI+ Introduction Figure 26.4 GDI+ coordinate system. 9

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.3Constructing the CheckWriter Application Figure 26.5 ACE table for the CheckWriter application. 10

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.3Constructing the CheckWriter Application Figure 26.6 CheckWriter application in Design view with PrintPreviewDialog. Added PrintPreviewDialog 11

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.3Constructing the CheckWriter Application Figure 26.7 Running template application. 12

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved PrintPreviewDialog s and PrintDocument s Document property: allows you to specify the document to preview PrintPreviewDialog : contains the UseAntiAlias property, which can smooth the text in the dialog – Set UseAntiAlias to true to enable smooth text 13

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure 26.8 Use a namespace in class FrmCheckWriter. Using namespace System.Drawing.Printing System.Drawing.Printing allows access to all services related to printing 14

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure 26.9 Rearranging and commenting the control declaration. 15

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure m_objFont created. Declaring a font object 16

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure objPrintDocument_PrintPage event handler. Empty PrintPage event handler 17

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application float data type: stores floating-point values; similar to double but less precise and requires less memory Use float to specify the coordinates for the left and top margins of the page to be printed. Margin values are determined using MarginBounds.Left and MarginBounds.Top 18

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure Variables created for objPrintDocument_PrintPage. Declare coordinatesSet left margin of pageSet top margin of page 19

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure foreach statement used for iteration. Declaring a foreach statement 20

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure Event handler objPrintDocument_PrintPage modified to draw border of check. Draw border of check 21

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application DrawRectangle takes five arguments: – Pens. Black object – x-coordinate of left edge of check – y-coordinate of top of check – this.Width ( this refers to the current object) – this.Height 22

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.5Creating an Event Handler for the CheckWriter Application Figure Event handler objPrintDocument_PrintPage modified to indicate that there are no more pages to print. Indicate no more pages to print 23

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Graphics Objects: Colors, Lines and Shapes Graphics : To draw, invoke a control’s CreateGraphics method – Example: Graphics objGraphics = pnlDisplay.CreateGraphics(); Colors : Created from a combination of alpha, red, green, and blue. Alpha determines opacity and ranges from 0 to 255 – Opacity : amount of transparency Blending of the color with any background color Dithering : Using small dots of existing colors to form a pattern that simulates the desired color. 24

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Graphics Objects: Colors, Lines and Shapes 25 Creating your own color: Color colorSilver; colorSilver = Color.FromArgb( 192, 192, 192 ); This version of the FromArgb method sets alpha to 255

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Graphics Objects: Colors, Lines and Shapes 26

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Graphics Objects: Colors, Lines and Shapes Pen : used to specify characteristics, such as the color and thickness of a line Brush : used to fill interior of a shape with a color or pattern. – Example, SolidBrush objBrush = new SolidBrush( Color.Orange ); 27

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Graphics Objects: Colors, Lines and Shapes 28

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.7Printing Each Control of the CheckWriter Application Figure Code to determine whether the current control is a Button. Ensure current control is not a Button 29

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.7Printing Each Control of the CheckWriter Application Figure switch statement to print controls. Determine current controlSet strLine to control’s textUnderline the text if displaying date from DateTimePicker Draw box around dollar amountSet the default font 30

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.7Printing Each Control of the CheckWriter Application DrawString : draws the specified string of text in the Graphics object – First argument: string to draw – Second argument: Font, specified by m_objFont – Third argument: specifies a Brush – Fourth and fifth arguments: x- and y-coordinates where the first character of the string prints 31

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.7Printing Each Control of the CheckWriter Application Figure Code to set string positions of the controls. Set horizontal location of current control Set vertical location of current control Print current control’s text 32

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Font Class 33 Note: Once a Font object has been created, its properties cannot be modified – You must create a new object to change the Font

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Font Class 34 Size returns the size of the font in design units SizeInPoints returns the size of the font in points Design units include Point, Display, Document, Inch, and Pixel Font class has several constructors Most require a font name such as SansSerif or Serif, a font size, and font style such as bold, italic, or underline

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Code that creates the PrintDocument object. Declaring a PrintDocument object 35

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Code that adds an event handler to the PrintDocument object. Adding an event handler for the PrintDocument object 36 Use class PrintPageEventHandler to associate the PrintPage event of the objPrintDocument object with the event handler specified

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Exiting the event handler if no printers are installed. Take no action if there are no printers installed 37

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Event handler btnPrint_Click modified to print the document. Printing the check 38

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Event handler btnPreview_Click modified to create PrintDocument and add PrintPage event handler. Creating a PrintDocument object Adding an event handler for the PrintDocument 39

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Exiting the print preview event handler if no printers are installed. 40

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Event handler btnPreview_Click modified to set the PrintPreviewDialog object’s Document property. Setting the document to preview 41

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Event handler btnPreview_Click modified to show preview dialog. Displaying the preview dialogue 42

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26.9Previewing and Printing the Check Figure Displaying an error message when no printers are installed. Method to display error message 43

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 44 CheckWriter.cs Part (1 of 10)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 45 CheckWriter.cs Part (2 of 10)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 46 CheckWriter.cs Part (3 of 10) Instance variable to store font

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 47 CheckWriter.cs Part (4 of 10)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 48 CheckWriter.cs Part (5 of 10) Event handler indicating what to print Variable to store left margin value Variable to store top margin value Looping through each control on the Form

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 49 CheckWriter.cs Part (6 of 10) Underlining text Drawing a box around text Using the control’s font

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 50 CheckWriter.cs Part (7 of 10) Printing textDrawing a box around the check Indicate that there are no more pages

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 51 CheckWriter.cs Part (8 of 10) Create a PrintDocument object Add an event handler for the PrintDocument object Display an error message if no printers are installed Print the Check

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 52 CheckWriter.cs Part (9 of 10) Create a PrintDocument object Add an event handler for the PrintDocument object Display error message if no printers are installed Show preview in dialog

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline 53 CheckWriter.cs Part (10 of 10)