Exemple #1
0
        public float CalculateHeight()
        {
            float width        = this.DefaultPageSettings.PaperSize.Width;
            float headerHeight = 0;

            if (Header != null)
            {
                headerHeight = Header.CalculateHeight(g, Left, width);
            }
            float yPos          = Top + headerHeight;
            int   calPrintIndex = 0;

            while (calPrintIndex < _printElements.Count)
            {
                PrintElement element = (PrintElement)_printElements[_printIndex];
                float        height  = element.CalculateHeight(g, Left, width);
                yPos += height;
                calPrintIndex++;
            }
            float footerHeight = 0;

            if (Footer != null)
            {
                footerHeight = Footer.CalculateHeight(g, Left, width);
            }
            yPos += footerHeight;
            yPos += Top;
            return(yPos);
        }
Exemple #2
0
        public void AddPrintObject(IPrintable printObject)
        {
            PrintElement element = new PrintElement(printObject);

            element.Print(g);

            _printElements.Add(element);
        }
Exemple #3
0
 private void InitEngine(string printerName  = null,
                         PrintElement header = null, PrintElement footer = null, float top = 0, float left = 0, float right = 0)
 {
     if (!string.IsNullOrEmpty(printerName))
     {
         this.PrinterSettings.PrinterName = printerName;
     }
     Header         = header;
     Footer         = footer;
     _printIndex    = 0;
     _printElements = new ArrayList();
     g     = this.PrinterSettings.CreateMeasurementGraphics();
     Top   = top;
     Left  = left;
     Right = right;
 }
Exemple #4
0
        // Print...
        public void Print(PrintElement element, Graphics graphics)
        {
            // tell the engine to draw a header... Arial
            Font  font      = new Font("Arial", 10);
            Font  headFont  = new Font("Arial", 12, FontStyle.Bold);
            SizeF sf        = graphics.MeasureString("Customer ID", font);
            float maxLength = sf.Width;

            element.AddMiddleText("Customer", headFont);
            // now, draw the data...
            element.AddPairText("Customer ID", Id.ToString(), maxLength, font, font);
            element.AddPairText("Name", FirstName + " " + LastName, maxLength, font, font);
            element.AddPairText("Company", Company, maxLength, font, font);
            element.AddPairText("E-mail", Email, maxLength, font, font);
            element.AddPairText("Phone", Phone, maxLength, font, font);
            // finally, add a blank line...
            //element.AddText("", font);
        }
Exemple #5
0
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            float yPos           = Top;// +5.9f;
            bool  morePages      = false;
            int   elementsOnPage = 0;
            int   printIndex     = 0;

            while (printIndex < _printObjects.Count)
            {
                IPrintable   printObject  = (IPrintable)_printObjects[printIndex];
                PrintElement printElement = new PrintElement(printObject);
                printElement.Print(null);
                printElement.Draw(Left, yPos, Right, e.PageBounds.Width, e.Graphics);
                yPos += this.Height;
                printIndex++;
                elementsOnPage++;
            }
            e.HasMorePages = morePages;
        }
Exemple #6
0
        // ShowPreview - show a print preview...
        //public void ShowPreview()
        //{
        //    // now, show the print dialog...
        //    PrintPreviewDialog dialog = new PrintPreviewDialog();
        //    dialog.Document = this;

        //    // show the dialog...
        //    dialog.ShowDialog();
        //}
        // OnBeginPrint - called when printing starts

        //protected override void OnBeginPrint(PrintEventArgs e)
        //{

        //}

        // OnPrintPage - called when printing needs to be done...
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            //foreach (IPrintable printObject in _printObjects)
            //{
            //    PrintElement element = new PrintElement(printObject);
            //    _printElements.Add(element);
            //    element.Print(e.Graphics);
            //}

            float headerHeight = 0;

            if (Header != null)
            {
                headerHeight = Header.CalculateHeight(e.Graphics, Left, e.PageBounds.Width);
                Header.Draw(Left, Top, Right, e.PageBounds.Width, e.Graphics);
            }
            float yPos           = Top + headerHeight;
            bool  morePages      = false;
            int   elementsOnPage = 0;

            while (_printIndex < _printElements.Count)
            {
                PrintElement element = (PrintElement)_printElements[_printIndex];
                float        height  = element.CalculateHeight(e.Graphics, Left, e.PageBounds.Width);
                element.Draw(Left, yPos, Right, e.PageBounds.Width, e.Graphics);
                yPos += height;
                _printIndex++;
                elementsOnPage++;
            }
            float footerHeight = 0;

            if (Footer != null)
            {
                footerHeight = Footer.CalculateHeight(e.Graphics, Left, e.PageBounds.Width);
                Footer.Draw(Left, yPos, Right, e.PageBounds.Width, e.Graphics);
            }
            e.HasMorePages = morePages;
            yPos          += footerHeight;
        }
Exemple #7
0
 public PrintEngine(string printerName, PrintElement header, PrintElement footer, float top, float left, float right)
 {
     InitEngine(printerName: printerName, header: header, footer: footer, top: top, left: left, right: right);
 }
Exemple #8
0
 public PrintEngine(PrintElement header, PrintElement footer, float top, float left, float right)
     : this(null, header, footer, top, left, right)
 {
 }
Exemple #9
0
 public PrintEngine(PrintElement header, PrintElement footer) : this(header, footer, 0, 0, 0)
 {
 }