Example #1
0
        private void btnEncodeOptions_Click(object sender, EventArgs e)
        {
            if (cmbEncoderType.SelectedItem == null)
            {
                MessageBox.Show(this, "Please select a barcode format first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                EncodingOptions options;
                switch ((BarcodeFormat)cmbEncoderType.SelectedItem)
                {
                case BarcodeFormat.QR_CODE:
                    options = new ZXing.QrCode.QrCodeEncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;

                case BarcodeFormat.PDF_417:
                    options = new ZXing.PDF417.PDF417EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;

                case BarcodeFormat.DATA_MATRIX:
                    options = new ZXing.Datamatrix.DatamatrixEncodingOptions
                    {
                        Height      = picEncodedBarCode.Height,
                        Width       = picEncodedBarCode.Width,
                        SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_SQUARE,
                        MinSize     = new Dimension(picEncodedBarCode.Width, picEncodedBarCode.Height)
                    };
                    break;

                default:
                    options = new EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;
                }
                var dlg = new EncodingOptionsForm
                {
                    Options = options
                };
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    EncodingOptions = dlg.Options;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnEncodeOptions_Click(object sender, EventArgs e)
        {
            if (cmbEncoderType.SelectedItem == null)
            {
                MessageBox.Show(this, "Please select a barcode format first.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            try
            {
                EncodingOptions options;
                switch ((BarcodeFormat)cmbEncoderType.SelectedItem)
                {
                case BarcodeFormat.QR_CODE:
                    options = EncodingOptions as ZXing.QrCode.QrCodeEncodingOptions ??
                              new ZXing.QrCode.QrCodeEncodingOptions
                    {
                        Height          = picEncodedBarCode.Height,
                        Width           = picEncodedBarCode.Width,
                        ErrorCorrection = ErrorCorrectionLevel.L
                    };
                    break;

                case BarcodeFormat.PDF_417:
                    options = EncodingOptions as ZXing.PDF417.PDF417EncodingOptions ??
                              new ZXing.PDF417.PDF417EncodingOptions
                    {
                        Height          = picEncodedBarCode.Height,
                        Width           = picEncodedBarCode.Width,
                        ErrorCorrection = PDF417ErrorCorrectionLevel.L0
                    };
                    break;

                case BarcodeFormat.DATA_MATRIX:
                    options = EncodingOptions as ZXing.Datamatrix.DatamatrixEncodingOptions ??
                              new ZXing.Datamatrix.DatamatrixEncodingOptions
                    {
                        Height      = picEncodedBarCode.Height,
                        Width       = picEncodedBarCode.Width,
                        SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_SQUARE
                    };
                    break;

                case BarcodeFormat.AZTEC:
                    options = EncodingOptions as ZXing.Aztec.AztecEncodingOptions ??
                              new ZXing.Aztec.AztecEncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width,
                    };
                    break;

                case BarcodeFormat.CODE_128:
                    options = EncodingOptions as ZXing.OneD.Code128EncodingOptions ??
                              new ZXing.OneD.Code128EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width,
                    };
                    break;

                default:
                    options = EncodingOptions ??
                              new EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;
                }
                var dlg = new EncodingOptionsForm
                {
                    Options  = options,
                    Renderer = Renderer
                };
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    EncodingOptions = dlg.Options;
                    Renderer        = dlg.Renderer;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void btnEncodeOptions_Click(object sender, EventArgs e)
 {
    if (cmbEncoderType.SelectedItem == null)
    {
       MessageBox.Show(this, "Please select a barcode format first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
       return;
    }
    try
    {
       EncodingOptions options;
       switch ((BarcodeFormat)cmbEncoderType.SelectedItem)
       {
          case BarcodeFormat.QR_CODE:
             options = new ZXing.QrCode.QrCodeEncodingOptions
                        {
                           Height = picEncodedBarCode.Height,
                           Width = picEncodedBarCode.Width
                        };
             break;
          case BarcodeFormat.PDF_417:
             options = new ZXing.PDF417.PDF417EncodingOptions
                        {
                           Height = picEncodedBarCode.Height,
                           Width = picEncodedBarCode.Width
                        };
             break;
          case BarcodeFormat.DATA_MATRIX:
             options = new ZXing.Datamatrix.DatamatrixEncodingOptions
             {
                Height = picEncodedBarCode.Height,
                Width = picEncodedBarCode.Width,
                SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_SQUARE,
                MinSize = new Dimension(picEncodedBarCode.Width, picEncodedBarCode.Height)
             };
             break;
          default:
             options = new EncodingOptions
                        {
                           Height = picEncodedBarCode.Height,
                           Width = picEncodedBarCode.Width
                        };
             break;
       }
       var dlg = new EncodingOptionsForm
                    {
                       Options = options
                    };
       if (dlg.ShowDialog(this) == DialogResult.OK)
       {
          EncodingOptions = dlg.Options;
       }
    }
    catch (Exception exc)
    {
       MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
 }