Exemplo n.º 1
0
        // Submit Button
        //     Starts the example code based on Form selections ---------------------------------------------

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            #region Variables

            bool   eject = false;
            string msg   = "";

            SampleCodeGraphics prn = null;

            #endregion

            #region Check Selections

            // Verifies that a printer has been selected
            try
            {
                if (cboPrn.SelectedIndex < 0)
                {
                    msg = "Error: A Printer has not been selected";
                    return;
                }

                #endregion


                #region Printing

                // Initialize the Print Side Class

                prn = new SampleCodeGraphics();

                // Determines the printing type

                SampleCodeDrawConfiguration config = new SampleCodeDrawConfiguration();
                config.StringLabelText = txtTextInput.Text;
                config.LabelLocation   = new Point(50, 465);

                if (openFileDialogBackground.FileName.EndsWith(".bmp") || openFileDialogBackground.FileName.EndsWith(".png"))
                {
                    config.BackgroundImageData =
                        new ZBRGraphics().AsciiEncoder.GetBytes(openFileDialogBackground.FileName);

                    config.BackgroundImageRect = new Rectangle(0, 0, 1024, 648);
                }

                if (openFileDialog1.FileName.EndsWith(".bmp") || openFileDialog1.FileName.EndsWith(".png"))
                {
                    config.ImageData =
                        new ZBRGraphics().AsciiEncoder.GetBytes(openFileDialog1.FileName);

                    config.ImageLocationRect = new Rectangle(50, 50, 400, 400);
                }
                if (SigMoves > 0)
                {
                    Bitmap   signbitmap = new Bitmap(240, 80, PixelFormat.Format32bppArgb); //Format32bppArgb for composite
                    Graphics g          = Graphics.FromImage(signbitmap);
                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    for (int i = 1; i < SigMoves; i++)
                    {
                        g.DrawLine(blackPen, this.SigArrayX[i - 1], this.SigArrayY[i - 1], this.SigArrayX[i], this.SigArrayY[i]);
                    }
                    signbitmap.Save(Application.StartupPath + "signature.png", ImageFormat.Png);

                    config.SignatureImageData =
                        new ZBRGraphics().AsciiEncoder.GetBytes(Application.StartupPath + "signature.png");
                    config.SignatureImageRect = new Rectangle(10, 500, 240, 80);
                }

                prn.PrintFrontSideOnly(this.cboPrn.Text,
                                       config,
                                       out msg);
                if (msg == "")
                {
                    this.lblStatus.Text = "No Errors";
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                MessageBox.Show(ex.ToString(), "btnSubmit_Click threw exception");
            }
            finally
            {
                if (msg != "")
                {
                    this.lblStatus.Text = msg;
                }

                prn = null;
            }

            #endregion
        }
Exemplo n.º 2
0
        /**************************************************************************************************
         * Function Name: PrintSingleSideJob
         *
         * Purpose: Performs the necessary tasks to define a single-sided print job, and send the job
         *           to the selected printer.
         *
         * Parameters: drvName = string containing name of selected printer
         *             DrawObject = SampleCodeDrawConfiguration object with details about the printed card data
         *             msg = string containing an error message if an error occurs.
         *
         * Returns: None
         *
         * History:
         * Date             Who             Comment
         * 08/01/2011       ACT             Function creation.
         ***************************************************************************************************/
        public void PrintFrontSideOnly(string drvName, SampleCodeDrawConfiguration drawObject, out string msg)
        {
            int         errValue; // value of 0 indicates no errors
            ZBRGraphics graphics = new ZBRGraphics();
            IntPtr      hDC      = IntPtr.Zero;

            msg = string.Empty;
            try
            {
                if (graphics.InitGraphics(graphics.AsciiEncoder.GetBytes(drvName), out errValue) == 0)
                {
                    msg = "Printing InitGraphics Error: " + errValue.ToString();
                    return;
                }

                //// Places an Image based on the background selected
                if (drawObject.BackgroundImageData != null)
                {
                    if (graphics.DrawImage(drawObject.BackgroundImageData, drawObject.BackgroundImageRect.X,
                                           drawObject.BackgroundImageRect.Y, drawObject.BackgroundImageRect.Width, drawObject.BackgroundImageRect.Height,
                                           out errValue) == 0)
                    {
                        msg = "Printing DrawImage Error: " + errValue.ToString();
                        return;
                    }
                }



                //// Places an Image from a file into the Graphics Buffer
                if (drawObject.ImageData != null)
                {
                    if (graphics.DrawImage(drawObject.ImageData, drawObject.ImageLocationRect.X,
                                           drawObject.ImageLocationRect.Y, drawObject.ImageLocationRect.Width, drawObject.ImageLocationRect.Height, out errValue) == 0)
                    {
                        msg = "Printing DrawImage Error: " + errValue.ToString();
                        return;
                    }
                }


                // Draws Text into the Graphics Buffer
                int fontStyle = FONT_BOLD;

                if (graphics.DrawText(drawObject.LabelLocation.X, drawObject.LabelLocation.Y,
                                      graphics.AsciiEncoder.GetBytes(drawObject.StringLabelText), graphics.AsciiEncoder.GetBytes("Arial"), 12,
                                      fontStyle, 0x000000, out errValue) == 0)
                {
                    msg = "Printing DrawText Error: " + errValue.ToString();
                    return;
                }


                //// Places an Image from a file into the Graphics Buffer
                if (drawObject.SignatureImageData != null)
                {
                    if (graphics.DrawImage(drawObject.SignatureImageData, drawObject.SignatureImageRect.X,
                                           drawObject.SignatureImageRect.Y, drawObject.SignatureImageRect.Width * 2, drawObject.SignatureImageRect.Height * 2, out errValue) == 0)
                    {
                        msg = "Printing DrawImage Error: " + errValue.ToString();
                        return;
                    }
                }

                // Prints data from the Graphics and Monochrome Buffers (Front Side)
                if (graphics.PrintGraphics(out errValue) == 0)
                {
                    msg = "Printing PrintGraphics Error: " + errValue.ToString();
                    return;
                }
            }
            catch (Exception ex)
            {
                msg += "PrintFrontSideOnly threw exception " + ex.ToString();
            }
            finally
            {
                // Starts the printing process and releases the Graphics Buffer
                if (graphics.CloseGraphics(out errValue) == 0)
                {
                    msg = "Printing CloseGraphics Error: " + errValue.ToString();
                }
            }
        }