- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
print barcode vb.net CHA PTE R 18 in Visual C#
CHA PTE R 18 Data Matrix Generator In Visual C# Using Barcode maker for .NET Control to generate, create Data Matrix image in Visual Studio .NET applications. www.OnBarcode.comRecognizing Data Matrix 2d Barcode In Visual C#.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comODDS AND ENDS .NET
Paint Code 128C In C#.NET Using Barcode generator for VS .NET Control to generate, create Code128 image in .NET applications. www.OnBarcode.comCreate Barcode In Visual C# Using Barcode generator for Visual Studio .NET Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comThese event handlers establish the required printing support for the parent form. The printing logic for the child form is presented next. 18.1.2 DRAWING A PRINT PAGE With our user interface logic in place, we are ready to implement the printing of a page. This is done using the PrintPageEventArgs parameter provided to the PrintPage event handler. This class is summarized in .NET Table 18.1. Paint Matrix Barcode In Visual C# Using Barcode drawer for .NET Control to generate, create 2D Barcode image in .NET applications. www.OnBarcode.comECC200 Printer In Visual C#.NET Using Barcode creation for .NET Control to generate, create Data Matrix ECC200 image in .NET framework applications. www.OnBarcode.com.NET Table 18.1 PrintPageEventArgs class
QR Code Creator In Visual C#.NET Using Barcode printer for Visual Studio .NET Control to generate, create Denso QR Bar Code image in VS .NET applications. www.OnBarcode.comPlanet Drawer In Visual C#.NET Using Barcode maker for .NET Control to generate, create USPS PLANET Barcode image in Visual Studio .NET applications. www.OnBarcode.comThe PrintPageEventArgs class represents an event argument containing information required for printing pages to a printer. This class is part of the System.Drawing.Printing namespace, and inherits from the System.EventArgs class. Cancel Gets or sets whether the print job should be cancelled. Gets the Graphics object on which to paint the page to print. Gets or sets whether an additional page should be printed after the current one. Gets the printable area of a page, which is the rectangle within the margins of the page. Gets the page area, which is the rectangle representing the entire page. Gets the PageSettings object representing the settings for the current page. Create DataMatrix In VS .NET Using Barcode maker for .NET framework Control to generate, create ECC200 image in Visual Studio .NET applications. www.OnBarcode.comDraw ECC200 In Objective-C Using Barcode generator for iPad Control to generate, create Data Matrix 2d barcode image in iPad applications. www.OnBarcode.comGraphics
Barcode Decoder In C#.NET Using Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in VS .NET applications. www.OnBarcode.comQR Code Creator In VS .NET Using Barcode generation for ASP.NET Control to generate, create QR Code image in ASP.NET applications. www.OnBarcode.comHasMorePages Public Properties MarginBounds
Barcode Maker In Objective-C Using Barcode generator for iPad Control to generate, create Barcode image in iPad applications. www.OnBarcode.comPDF-417 2d Barcode Printer In Java Using Barcode maker for BIRT reports Control to generate, create PDF417 image in BIRT reports applications. www.OnBarcode.comPageBounds
Matrix Barcode Creator In Java Using Barcode drawer for Java Control to generate, create 2D image in Java applications. www.OnBarcode.comMake Code 3/9 In Java Using Barcode generation for BIRT reports Control to generate, create Code-39 image in Eclipse BIRT applications. www.OnBarcode.comPageSettings
Data Matrix Drawer In None Using Barcode generator for Online Control to generate, create ECC200 image in Online applications. www.OnBarcode.comCreate Universal Product Code Version A In Visual Studio .NET Using Barcode encoder for ASP.NET Control to generate, create UPC Symbol image in ASP.NET applications. www.OnBarcode.comWe will implement a PrintCurrentImage method in the MainForm class to make use of this parameter. Internally, this will draw the photograph using the provided Graphics object, and use an internal PrintTextString method to draw the individual properties for the photograph. Code 39 Full ASCII Generation In Objective-C Using Barcode creator for iPad Control to generate, create Code-39 image in iPad applications. www.OnBarcode.comBarcode Generator In .NET Framework Using Barcode encoder for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comIMPLEMENT THE PRINTCURRENTIMAGE METHOD Action 1 In the MainForm.cs code window, indicate that we will use members of the System.Drawing.Printing
Result
using System.Drawing.Printing; namespace. 2 Add a PrintCurrentImage method that accepts a PrintPageEventArgs object as a parameter.
public void PrintCurrentImage (PrintPageEventArgs e) { PRINTING
IMPLEMENT THE PRINTCURRENTIMAGE METHOD (continued) Action 3 If there is no current photo, then abort the print operation. Result Photograph photo = _album.CurrentPhoto; if (photo == null) { // nothing to print, so abort e.Cancel = true; return; } // Establish some useful shortcuts float leftMargin = e.MarginBounds.Left; float rightMargin = e.MarginBounds.Right; float topMargin = e.MarginBounds.Top; float bottomMargin = e.MarginBounds.Bottom; float printableWidth = e.MarginBounds.Width; float printableHeight = e.MarginBounds.Height; Graphics g = e.Graphics; Font printFont = new Font("Times New Roman", 11); float fontHeight = printFont.GetHeight(g); float spaceWidth = g.MeasureString(" ", printFont).Width; Otherwise, create some shortcuts for the margins of the page and the Graphics object.
Create a Font object: a. Use 11 point Times New Roman. b. Use the GetHeight method to determine the height of each line of text. c. Use the MeasureString method to determine the size of a space. Determine the correct length so that the image can be drawn into a box which is 75% of the shortest side of the page. Note: This logic accounts for both landscape and portrait page orientation. The xPos and yPos variables represent where the first line of text should be drawn. // Draw image in box 75% of shortest side float imageBoxLength; float xPos = leftMargin; float yPos = topMargin + fontHeight; if (printableWidth < printableHeight) { imageBoxLength = printableWidth * 75/100; yPos += imageBoxLength; } else { imageBoxLength = printableHeight * 75/100; xPos += imageBoxLength + spaceWidth; } // Draw image at start of the page Rectangle imageBox = new Rectangle((int)leftMargin + 1, (int)topMargin + 1, (int)imageBoxLength, (int)imageBoxLength); g.DrawImage(photo.Image, photo.ScaleToFit(imageBox)); // Determine rectangle for text RectangleF printArea = new RectangleF(xPos, yPos, rightMargin - xPos, bottomMargin - yPos); Draw the image into a box of the determined size.
Determine the RectangleF object where all text should be drawn.
CHA PTE R 18
ODDS AND ENDS .NET
IMPLEMENT THE PRINTCURRENTIMAGE METHOD (continued) Action 9 Print the file name, caption, photographer, and notes properties for the photograph onto the page. How-to
Result
PrintTextString(g, printFont, "FileName:", photo.FileName, ref printArea); PrintTextString(g, printFont, "Caption:", photo.Caption, ref printArea); PrintTextString(g, printFont, "Photographer:", photo.Photographer, ref printArea); PrintTextString(g, printFont, "Notes:", photo.Notes, ref printArea); } Use the yet-to-be-written PrintTextString method.
The PrintTextString method is implemented by the subsequent steps. Note that our implementation prints the given string across multiple lines if necessary by drawing each word in the text string separately. Also note that the printArea variable is passed by reference. This is required in order to modify the printable area for text strings in the PrintTextString method. Since the RectangleF structure is a value type, it is normally passed by value. IMPLEMENT THE PRINTTEXTSTRING METHOD Action 10 Add a PrintTextString method to the MainForm.cs code window. Result protected void PrintTextString( Graphics g, Font printFont, string name, string text, ref RectangleF printArea) { // Establish some useful shortcuts float leftMargin = printArea.Left; float rightMargin = printArea.Right; float topMargin = printArea.Top; float bottomMargin = printArea.Bottom; float fontHeight = printFont.GetHeight(g); float xPos = printArea.Left; float yPos = topMargin + fontHeight; float spaceWidth = g.MeasureString(" ", printFont).Width; float nameWidth = g.MeasureString(name, printFont).Width; if (!printArea.Contains(xPos + nameWidth, yPos)) { // Does not fit, so abort return; } Create some local variables for the margins of the printable area. Also determine the height of the font and the coordinates where the text should be drawn. Find the width of a space and the name for the text string.
|
|