|
|
Print Object FactoryAdd-in for Visual Studio .NET to Create Print Classes Automatically | | Print Object Factory is an add-in for Visual Studio .NET that allows you to automatically create either a VB.NET or C#.NET class for printing to a complex, pre-printed form. Many times, you will have to print data, that was retrieved from a variety of sources, and you have assembled the data in memory variables, strings, etc. Next, you are presented with printing those multiple data objects in one to many places, literally all over the page. Obviously, you can purchase expensive tools that you can use to lay out your form and possibly print it from memory, but they have a learning curve, sometimes lack design time testing, such as Crystal Reports as delivered with .NET.
Print Object Factory is designed to take the guesswork out of placing the data on the print page, regardless of the number of data objects and where they are placed respectively. To create a print class, that prints your data, exactly where you tell it to, you simply follow the steps listed below, and the complete class will be added to your VB or C# project. You can Download a Free 30-day trial version of Print Object Factory.
- Select the destination printer.
- Measure, with a ruler, using inches and fractions of inches, from 1/32 to 10 15/16, etc., noting where you want each "data object" to print on a form.
- Enter those measurements into the Print Designer, shown in Figure 1, along with test data for each of the data objects.
- The objects will be added to a ListView, where they can be easily edited.
- You can save the contents of the ListView automatically into an XML file, that can be loaded and modified, if you need to make an adjustment and recreate your class in the future.
- Check any or all of the data objects that you want to Preview or Print in test mode, and click the Preview or Print button as shown in Figure 2.
- Once the objects are printing where you want them to, on the pre-printed page, simply enter the name for your new class and click the Add to Project button. The Designer will create the complete class, ready for instantiation and calling, and add the new class to your project.
- You can choose Font, Font Size, Bold, Underline, Italics, and Strikethrough.
- You can even design your own form by telling the designer to draw lines and boxes, specifying the pen width of the line.
- Finally, each data object or line or box can be a different color if you desire.
You will be amazed that you can design a print class to place 15-20 data objects on a complex form, in a little more time than it takes you to measure where they are to fit on the form. When the print class is added to your project, and called with real data objects, that data will print exactly where you want it to print the first time you run the application. Best of all you can know your data will be positioned on the form properly without ever running you application. Your can view the code for VB.NET or C#.NET, click the respective link.
Figure 1 - Designing the data objects.

Figure 2 - Select Data Objects and Preview the Printout.

Figure 3 - Preview of the Printed Form.

Top of Page
Figure 4 - VB Code Class Generated by Print Object Factory.
''' This is a standalone print class.
''' The constructor accepts the text for the print objects,
''' Once instantiated,
''' Simply call the Print or Preview method.
Public Class CRelialblePrintObject
Dim previewDialog As New PrintPreviewDialog
WithEvents PrintDoc As Printing.PrintDocument
Public Sub New( _
ByVal tbnameBillTo As String, _
ByVal tbnameShipTo As String, _
ByVal tbnameInvoice As String, _
ByVal tbnameTimeOut As String, _
ByVal tbnameTimeIn As String, _
ByVal tbnameElapsed As String, _
ByVal tbnameJobPhone As String, _
ByVal tbnameCheckedInBy As String, _
ByVal tbnameDLNumber As String, _
ByVal tbnameAgent As String, _
ByVal tbnamePONumber As String, _
ByVal tbnameDueInTime As String, _
ByVal tbnameJobLocation As String, _
ByVal tbnameTotalDesc As String, _
ByVal tbnameTaxid As String, _
ByVal tbnamePaidOption As String, _
ByVal tbnameDetailLines As String, _
ByVal tbnameWrittenBy As String)
' These are your data objects
AddObjectToList("Courier New", 11.25, 106.462472088623, _
125.249989306641, 100.199973730469, 100.199991445312, _
tbnameBillTo, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 106.462472088623, _
237.974979682617, 100.199973730469, 100.199991445312, _
tbnameShipTo, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 588.674845666504, _
87.6749925146484, 100.199973730469, 100.199991445312, _
tbnameInvoice, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 588.674845666504, _
162.824986098633, 100.199973730469, 100.199991445312, _
tbnameTimeOut, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 588.674845666504, _
125.249989306641, 100.199973730469, 100.199991445312, _
tbnameTimeIn, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 588.674845666504, _
187.874983959961, 100.199973730469, 100.199991445312, _
tbnameElapsed, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 12.5249967163086, _
356.962469523926, 100.199973730469, 100.199991445312, _
tbnameJobPhone, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 200.399947460937, _
325.649972197266, 100.199973730469, 100.199991445312, _
tbnameCheckedInBy, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 200.399947460937, _
356.962469523926, 100.199973730469, 100.199991445312, _
tbnameDLNumber, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 407.062393280029, _
325.649972197266, 100.199973730469, 100.199991445312, _
tbnameAgent, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 407.062393280029, _
356.962469523926, 100.199973730469, 100.199991445312, _
tbnamePONumber, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 607.462340740967, _
356.962469523926, 100.199973730469, 100.199991445312, _
tbnameDueInTime, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 607.462340740967, _
325.649972197266, 100.199973730469, 100.199991445312, _
tbnameJobLocation, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 9.75, 538.574767181923, _
814.124899833984, 100.199956685009, 100.199987671875, _
tbnameTotalDesc, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 576.149848950195, _
244.237479147949, 100.199973730469, 100.199991445312, _
tbnameTaxid, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 576.149848950195, _
275.549976474609, 100.199973730469, 100.199991445312, _
tbnamePaidOption, False, False, False, Text", 1, "Black")
AddObjectToList("Courier New", 9.75, 12.5249945856261, _
413.324949146484, 100.199956685009, 100.199987671875, _
tbnameDetailLines, False, False, False, "Text", 1, "Black")
AddObjectToList("Courier New", 11.25, 12.5249967163086, _
325.649972197266, 100.199973730469, 100.199991445312, _
tbnameWrittenBy, False, False, False, "Text", 1, "Black")
PrintDoc = New Printing.PrintDocument
End Sub
Public Structure PrintObjects
Dim FontName As String
Dim FontSize As Single
Dim XPos As Single
Dim YPos As Single
Dim yHeight As Single
Dim xWidth As Single
Dim FontBold As Boolean
Dim FontUnderlne As Boolean
Dim FontItalic As Boolean
Dim Text As String
Dim Name As String
Dim Left As Single
Dim Top As Single
Dim Height As Single
Dim Width As Single
Dim HCI As Single
Dim VCI As Single
Dim CharWidth As Single
Dim LineHeight As Single
Dim Points As Single
Dim Box As String
Dim PenWidth As Single
Dim Color As String
End Structure
Public printObjectArray As New ArrayList()
Private printObject As PrintObjects
Public Sub AddObjectToList(ByVal FontName As String, _
ByVal FontSize As Single, ByVal Left As Single, _
ByVal Top As Single, ByVal Height As Single, _
ByVal Width As Single, ByVal TextString As String, _
ByVal FontBold As Boolean, ByVal FontItalic As Boolean, _
ByVal FontUnderline As Boolean, ByVal Box As String, _
ByVal PenWidth As Single, ByVal Color As String)
With printObject
.FontName = FontName
.FontSize = FontSize
.XPos = Left
.YPos = Top
.xWidth = Width
.yHeight = Height
.Text = TextString
.FontBold = FontBold
.FontItalic = FontItalic
.FontUnderlne = FontUnderline
.Box = Box
.PenWidth = PenWidth
.Color = Color
End With
printObjectArray.Add(printObject)
End Sub
Public Sub Print()
Dim PD As New Printing.PrintDocument()
PD.Print()
End Sub
Public Sub Preview()
PrintDoc.DocumentName = "Print Object Test"
previewDialog.Document = PrintDoc
previewDialog.ShowDialog()
PrintDoc.Dispose()
previewDialog.Dispose()
End Sub
Private Sub PrintDoc_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDoc.PrintPage
Dim i As Integer
For i = 0 To printObjectArray.Count - 1
printObject = printObjectArray.Item(i)
With printObject
Dim fontAttributes As System.Drawing.FontStyle = _
(IIf(printObject.FontBold, 1, 0) Or _
IIf(printObject.FontItalic, 2, 0) Or _
IIf(printObject.FontUnderlne, 4, 0))
Dim printFont As Font
If fontAttributes <> 0 And fontAttributes <> _
FontStyle.Regular Then
printFont = New Font(.FontName, FontSize, fontAttributes)
Else
printFont = New Font(.FontName, FontSize)
End If
If .Box = "Box" Then
Dim c As Color
c = Color.FromName(.Color)
Dim myPen As New Pen(c, PenWidth)
e.Graphics.DrawRectangle(myPen, printObject.XPos, _
printObject.YPos, _
printObject.xWidth, printObject.yHeight)
ElseIf .Box = "Line" Then
Dim c As Color
c = Color.FromName(.Color)
Dim myPen As New Pen(c, PenWidth)
e.Graphics.DrawLine(myPen, printObject.XPos, _
printObject.YPos, _
printObject.XPos + printObject.xWidth, _
printObject.YPos + printObject.yHeight)
ElseIf .Box = "Text" Then
Dim b As New SolidBrush(Color.FromName(.Color))
e.Graphics.DrawString(printObject.Text, printFont, _
b, .XPos, .YPos, New StringFormat())
End If
End With
Next i
e.HasMorePages = False
End Sub
End Class
|
Top of Page
Figure 5 - C# Code Class Generated by Print Object Factory.
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace PrintObjectCSharp
{
/// <summary>
/// Standalone print object. Passing the text string
/// required by each object to the constructor sets up
/// the class for printing the strings at the exact point
/// at which you designed it to. Once instantiated, you
/// need only call the Print or Preview methods.
///
public class CPrintObject
{
private PrintDocument PrintDoc;
private PrintPreviewDialog previewDialog;
private ArrayList printObjectArray = new ArrayList();
private PrintObjects printObject;
private struct PrintObjects
{
public string FontName;
public float FontSize;
public float XPos;
public float YPos;
public float yHeight;
public float xWidth;
public bool FontBold;
public bool FontUnderline;
public bool FontItalic;
public string Text;
public string Box;
public float PenWidth;
public string Color;
}
public CPrintObject(
string tbnameBillTo,
string tbnameShipTo,
string tbnameInvoice,
string tbnameTimeOut,
string tbnameTimeIn,
string tbnameElapsed,
string tbnameJobPhone,
string tbnameCheckedInBy,
string tbnameDLNumber,
string tbnameAgent,
string tbnamePONumber,
string tbnameDueInTime,
string tbnameJobLocation,
string tbnameTaxid,
string tbnamePaidOption,
string tbnameWrittenBy,
string tbnameDetailLines,
string tbnameTotalDesc)
{
AddObjectToList("Courier New",(float) 11.25,
(float) 106.462472088623,
(float) 125.249989306641,(float) 100.199973730469,
(float) 100.199991445312,tbnameBillTo,false,false,
false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 106.462472088623,
(float) 237.974979682617,(float) 100.199973730469,
(float) 100.199991445312,tbnameShipTo,false,
false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 588.674845666504,
(float) 87.6749925146484,(float) 100.199973730469,
(float) 100.199991445312,tbnameInvoice,false,false,
false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 588.674845666504,
(float) 162.824986098633,(float) 100.199973730469,
(float) 100.199991445312,tbnameTimeOut,false,false,false,
"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 588.674845666504,
(float) 125.249989306641,(float) 100.199973730469,
(float) 100.199991445312,tbnameTimeIn,false,
false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 588.674845666504,(float) 187.874983959961,
(float) 100.199973730469,(float) 100.199991445312,
tbnameElapsed,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 12.5249967163086,
(float) 356.962469523926,(float) 100.199973730469,
(float) 100.199991445312,tbnameJobPhone,false,
false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 200.399947460937,
(float) 325.649972197266,(float) 100.199973730469,
(float) 100.199991445312,tbnameCheckedInBy,
false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 200.399947460937,
(float) 356.962469523926,(float) 100.199973730469,
(float) 100.199991445312,tbnameDLNumber,
false,false,false,"Text", 1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 407.062393280029,(float) 325.649972197266,
(float) 100.199973730469,(float) 100.199991445312,
tbnameAgent,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 407.062393280029,(float) 356.962469523926,
(float) 100.199973730469,(float) 100.199991445312,
tbnamePONumber,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 594.937344024658,(float) 356.962469523926,
(float) 100.199973730469,(float) 100.199991445312,
tbnameDueInTime,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 607.462340740967,(float) 325.649972197266,
(float) 100.199973730469,(float) 100.199991445312,
tbnameJobLocation,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 576.149848950195,(float) 244.237479147949,
(float) 100.199973730469,(float) 100.199991445312,
tbnameTaxid,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 576.149848950195,(float) 275.549976474609,
(float) 100.199973730469,(float) 100.199991445312,
tbnamePaidOption,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 11.25,
(float) 12.5249967163086,(float) 325.649972197266,
(float) 100.199973730469,(float) 100.199991445312,
tbnameWrittenBy,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 9.75,
(float) 12.5249945856261,(float) 413.324949146484,
(float) 100.199956685009,(float) 100.199987671875,
tbnameDetailLines,false,false,false,"Text",1,"Black");
AddObjectToList("Courier New",(float) 9.75,
(float) 538.574767181923,(float) 814.124899833984,
(float) 100.199956685009,(float) 100.199987671875,
tbnameTotalDesc,false,false,false,"Text",1,"Black");
PrintDoc = new PrintDocument();
PrintDoc.PrintPage +=
new PrintPageEventHandler(thisOnPrintPage);
}
public void AddObjectToList(
string FontName,
float FontSize,
float Left,
float Top,
float Height,
float Width,
|
|