예제 #1
0
 protected virtual void Update()
 {
     if (string.IsNullOrEmpty(this.Value) || this.Symbology == null)
     {
         this.ElementFactory.ClearElements();
         this.Invalidate();
     }
     else
     {
         (this.Symbology as Symbology1D)?.ProcessValue(this.Value);
         PDF417 symbology = this.Symbology as PDF417;
         symbology?.PopulateMatrix(this.value, symbology.ECLevel, symbology.EncodingMode, symbology.Columns, symbology.Rows);
         (this.Symbology as QRCode)?.EncodeData(this.value);
         this.InvalidateMeasure();
         this.InvalidateArrange();
         this.UpdateLayout();
         this.Invalidate();
     }
 }
예제 #2
0
        protected virtual SizeF MeasureSymbology(SizeF availableSize)
        {
            Symbology1D symbology1 = this.Symbology as Symbology1D;

            if (symbology1 != null)
            {
                return(symbology1.MeasureContent((IMeasureContext) new MeasureContext(this.GetScaledFont(this.DpiScaleFactor.Height)), availableSize));
            }
            PDF417 symbology2 = this.Symbology as PDF417;

            if (symbology2 != null)
            {
                return(new SizeF((float)(symbology2.DataMatrix.GetLength(1) * symbology2.Module), (float)(symbology2.DataMatrix.GetLength(0) * symbology2.Module)));
            }
            QRCode symbology3 = this.Symbology as QRCode;

            if (symbology3 != null)
            {
                return(new SizeF((float)(symbology3.BinaryMatrix.GetLength(1) * symbology3.Module), (float)(symbology3.BinaryMatrix.GetLength(0) * symbology3.Module)));
            }
            return(SizeF.Empty);
        }
예제 #3
0
        public override void DpiScaleChanged(SizeF scaleFactor)
        {
            base.DpiScaleChanged(scaleFactor);
            Symbology1D symbology1 = this.Symbology as Symbology1D;

            if (symbology1 != null)
            {
                symbology1.Module = (int)Math.Round((double)symbology1.Module * ((double)this.DpiScaleFactor.Width / (double)this.previousDpi.Width));
            }
            PDF417 symbology2 = this.Symbology as PDF417;

            if (symbology2 != null)
            {
                symbology2.Module = (int)Math.Round((double)symbology2.Module * ((double)this.DpiScaleFactor.Width / (double)this.previousDpi.Width), MidpointRounding.AwayFromZero);
            }
            QRCode symbology3 = this.Symbology as QRCode;

            if (symbology3 != null)
            {
                symbology3.Module = (int)Math.Round((double)symbology3.Module * ((double)this.DpiScaleFactor.Width / (double)this.previousDpi.Width), MidpointRounding.AwayFromZero);
            }
            this.previousDpi = scaleFactor;
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Code128")
            {
                Code128 bc = new Code128();
                int     i;
                bc.BarcodeSubtype = (Code128Subtype)Enum.Parse(typeof(Code128Subtype), comboBox2.Text);
                int.TryParse(textBox3.Text, out i); bc.Height      = i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                bc.TextAbove   = checkBox2.Checked;
                bc.DisplayText = checkBox1.Checked;
                int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                try
                {
                    if (checkBox3.Checked)
                    {
                        try
                        {
                            string line;

                            System.IO.StreamReader file = new System.IO.StreamReader(textBox5.Text);
                            while ((line = file.ReadLine()) != null)
                            {
                                bc.SaveBarcodeToFile(line, String.Format("{0}\\{1}.{2}", Path.GetDirectoryName(textBox5.Text), line, "gif"));
                            }

                            file.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                        }
                    }
                    else
                    {
                        pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                        bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
                    }
                }
                catch (Exception) { }
            }
            ;
            if (comboBox1.Text == "Code39")
            {
                Code39 bc = new Code39();
                int    i;
                int.TryParse(textBox3.Text, out i); bc.Height      = i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                bc.TextAbove   = checkBox2.Checked;
                bc.DisplayText = checkBox1.Checked;
                int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            if (comboBox1.Text == "PDF417")
            {
                PDF417 bc = new PDF417();
                int    i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth   = i;
                int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            if (comboBox1.Text == "QRCode")
            {
                QRCode bc = new QRCode();
                int    i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                //int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                int.TryParse(textBox4.Text, out i); bc.ErrorCorrectionLevel = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            if (comboBox1.Text == "DataMatrix")
            {
                DataMatrix bc = new DataMatrix();
                int        i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                //int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                //int.TryParse(textBox4.Text, out i); bc.ErrorCorrectionLevel = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            //BarcodeGenerator BCG = new BarcodeGenerator();
            //BCG.BarcodeType = BarcodeType.Code39;
            //pictureBox1.Image = BCG.GetBarcodeImage(textBox1.Text);
            //textBox2.Text = BCG.TextWidth.ToString();

            //MessageBox.Show(NumberFormatInfo.CurrentInfo.PerMilleSymbol);
            //MessageBox.Show(NumberFormatInfo.CurrentInfo.NegativeInfinitySymbol);
            //MessageBox.Show((-1).ToString("x"));
        }
예제 #5
0
        private void btnGen_Click(object sender, EventArgs e)
        {
            Options opt     = (Options)cbType.SelectedItem;
            string  strCont = tbCon.Text.Trim();
            string  pic     = "D:\\Temp\\Barcode_" + DateTime.Now.ToString("MMddHHmmss") + ".jpg";

            picbc.Invalidate();
            if (strCont != "")
            {
                if (opt == null)
                {
                    MessageBox.Show("Please choice \"Label Type\"!!");
                }
                else
                {
                    switch (opt.Value)
                    {
                    case 1:
                    case 2:
                        Linear lb = new Linear();
                        if (opt.Value == 1)
                        {
                            lb.Type = BarcodeType.CODE39;
                            lb.Data = strCont.ToUpper();
                        }
                        else
                        {
                            lb.Type = BarcodeType.CODE128;
                            lb.Data = strCont;
                        }
                        if (cbox.Checked)
                        {
                            lb.ShowText = true;
                        }
                        else
                        {
                            lb.ShowText = false;
                        }
                        lb.BearerBarWidth = 2;
                        lb.BarHeight      = 50;
                        lb.drawBarcode(pic);

                        break;

                    case 3:
                        PDF417 p = new PDF417();
                        p.Data    = strCont;
                        p.Columns = 5;
                        p.Rows    = 10;
                        p.drawBarcode(pic);
                        break;

                    case 4:
                        DataMatrix dm = new DataMatrix();
                        dm.ModuleSize   = 8;
                        dm.RightMargin  = 6;
                        dm.LeftMargin   = 6;
                        dm.TopMargin    = 6;
                        dm.BottomMargin = 6;
                        dm.drawBarcode(pic);
                        break;

                    case 5:
                        QRCode qr = new QRCode();
                        qr.ModuleSize   = 7;
                        qr.RightMargin  = 3;
                        qr.LeftMargin   = 3;
                        qr.TopMargin    = 3;
                        qr.BottomMargin = 3;
                        qr.drawBarcode(pic);
                        break;

                    default:
                        break;
                    }
                    if (File.Exists(pic))
                    {
                        Bitmap bmp = new Bitmap(pic);
                        try
                        {
                            picbc.Width  = bmp.Width;
                            picbc.Height = bmp.Height;
                            int pw = (panel1.Width - picbc.Width) / 2;
                            int ph = (panel1.Height - picbc.Height) / 2;
                            picbc.Left  = pw;
                            picbc.Top   = ph;
                            picbc.Image = bmp;
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(err.Message);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Conten is empty!!");
            }
        }
예제 #6
0
        private void btnImprimirCodigoBarras_Click(object sender, System.EventArgs e)
        {
            CodigoBarras codigoBarras;
            switch (cboCodigoBarras.SelectedIndex)
            {
                case 0: codigoBarras = new EAN8(); break;
                case 1: codigoBarras = new EAN13();break;
                case 2: codigoBarras = new CODABAR();break;
                case 3: codigoBarras = new CODE39();break;
                case 4: codigoBarras = new CODE93();break;
                case 5: codigoBarras = new CODE128();break;
                case 6: codigoBarras = new ISBN();break;
                case 7: codigoBarras = new ITF();break;
                case 8: codigoBarras = new MSI();break;
                case 9: codigoBarras = new PDF417();break;
                case 10: codigoBarras = new PLESSEY();break;
                case 11: codigoBarras = new UPCA();break;
                case 12: codigoBarras = new UPCE();break;
                default: codigoBarras = new EAN13();break;
            }

            codigoBarras.Codigo = txtCodigoBarras.Text;

            // fonte
            if (rbtFonteNormal.Checked)
            {
                codigoBarras.Fonte = CodigoBarras.FonteLegenda.Normal;
            }
            else
            {
                codigoBarras.Fonte = CodigoBarras.FonteLegenda.Condensada;
            }

            // largura das barras
            if (rbtFina.Checked)
            {
                codigoBarras.Largura = CodigoBarras.LarguraBarra.Fina;
            }
            else if(rbtMedia.Checked)
            {
                codigoBarras.Largura = CodigoBarras.LarguraBarra.Media;
            }
            else
            {
                codigoBarras.Largura = CodigoBarras.LarguraBarra.Grossa;
            }

            // posicao legenda
            if (rbtCaracteresAbaixoCodigo.Checked)
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.Abaixo;
            }
            else if(rbtCaracteresAcimaCodigo.Checked)
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.Acima;
            }
            else if(rbtCaracteresAcimaAbaixoCodigo.Checked)
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.AcimaAbaixo;
            }
            else
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.Nenhuma;
            }

            try
            {
                miniPrinter.Imprimir(codigoBarras);
            }
            catch (BematechException erro)
            {
                MessageBox.Show(erro.Message, "TestMiniPrinter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }