コード例 #1
0
ファイル: Form1.cs プロジェクト: mxq00812314/MXQ
 private void btnEncodeQRCoder_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(txtContent.Text))
     {
         TipHelper.TipMsg(this, $"请输入标签内容!");
     }
     gbxQRCoder.BackgroundImage = GenerateQRCcodes(txtContent.Text, (int)numPixelsPerModule.Value);
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: mxq00812314/MXQ
 private void PrintCoder(Bitmap coderImage)
 {
     printCoderImage = coderImage;
     printDocument1  = new PrintDocument();
     printDocument1.PrintController = new StandardPrintController(); //不要打印进度框
     printDocument1.DefaultPageSettings.Landscape = false;           //设置打印横向还是纵向
     printDocument1.PrintPage += new PrintPageEventHandler(MyPrintDoc1_PrintPage);
     try
     {
         printDocument1.Print();
         printDocument1.PrintPage -= new PrintPageEventHandler(MyPrintDoc1_PrintPage);
     }
     catch (Exception ex)
     {
         TipHelper.TipMsg(this, $"打印异常:{ex.Message}");
     }
     printCoderImage = null;
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: mxq00812314/MXQ
        /// <summary>
        /// 输出条码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEncode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtContent.Text))
            {
                TipHelper.TipMsg(this, $"请输入标签内容!");
            }

            errorProvider1.Clear();
            int W = Convert.ToInt32(this.txtWidth.Text.Trim());
            int H = Convert.ToInt32(this.txtHeight.Text.Trim());

            bar.Alignment = BarcodeLib.AlignmentPositions.CENTER;

            //条形码对齐
            switch (cbBarcodeAlign.SelectedItem.ToString().Trim().ToLower())
            {
            case "left": bar.Alignment = BarcodeLib.AlignmentPositions.LEFT; break;

            case "right": bar.Alignment = BarcodeLib.AlignmentPositions.RIGHT; break;

            default: bar.Alignment = BarcodeLib.AlignmentPositions.CENTER; break;
            }

            BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;
            switch (cbEncodeType.SelectedItem.ToString().Trim())
            {
            case "UPC-A": type = BarcodeLib.TYPE.UPCA; break;

            case "UPC-E": type = BarcodeLib.TYPE.UPCE; break;

            case "UPC 2 Digit Ext.": type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT; break;

            case "UPC 5 Digit Ext.": type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT; break;

            case "EAN-13": type = BarcodeLib.TYPE.EAN13; break;

            case "JAN-13": type = BarcodeLib.TYPE.JAN13; break;

            case "EAN-8": type = BarcodeLib.TYPE.EAN8; break;

            case "ITF-14": type = BarcodeLib.TYPE.ITF14; break;

            case "Codabar": type = BarcodeLib.TYPE.Codabar; break;

            case "PostNet": type = BarcodeLib.TYPE.PostNet; break;

            case "Bookland/ISBN": type = BarcodeLib.TYPE.BOOKLAND; break;

            case "Code 11": type = BarcodeLib.TYPE.CODE11; break;

            case "Code 39": type = BarcodeLib.TYPE.CODE39; break;

            case "Code 39 Extended": type = BarcodeLib.TYPE.CODE39Extended; break;

            case "Code 39 Mod 43": type = BarcodeLib.TYPE.CODE39_Mod43; break;

            case "Code 93": type = BarcodeLib.TYPE.CODE93; break;

            case "LOGMARS": type = BarcodeLib.TYPE.LOGMARS; break;

            case "MSI": type = BarcodeLib.TYPE.MSI_Mod10; break;

            case "Interleaved 2 of 5": type = BarcodeLib.TYPE.Interleaved2of5; break;

            case "Standard 2 of 5": type = BarcodeLib.TYPE.Standard2of5; break;

            case "Code 128": type = BarcodeLib.TYPE.CODE128; break;

            case "Code 128-A": type = BarcodeLib.TYPE.CODE128A; break;

            case "Code 128-B": type = BarcodeLib.TYPE.CODE128B; break;

            case "Code 128-C": type = BarcodeLib.TYPE.CODE128C; break;

            case "Telepen": type = BarcodeLib.TYPE.TELEPEN; break;

            case "FIM": type = BarcodeLib.TYPE.FIM; break;

            case "Pharmacode": type = BarcodeLib.TYPE.PHARMACODE; break;

            default: TipHelper.TipMsg(this, "请指定条码编码类型!"); break;
            }

            try
            {
                if (type != BarcodeLib.TYPE.UNSPECIFIED)
                {
                    try
                    {
                        bar.BarWidth = textBoxBarWidth.Text.Trim().Length < 1 ? null : (int?)Convert.ToInt32(textBoxBarWidth.Text.Trim());
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Unable to parse BarWidth: " + ex.Message, ex);
                    }
                    try
                    {
                        bar.AspectRatio = textBoxAspectRatio.Text.Trim().Length < 1 ? null : (double?)Convert.ToDouble(textBoxAspectRatio.Text.Trim());
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Unable to parse AspectRatio: " + ex.Message, ex);
                    }

                    bar.IncludeLabel = this.chkGenerateLabel.Checked;

                    bar.RotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), this.cbRotateFlip.SelectedItem.ToString(), true);

                    //标签对齐和位置
                    switch (this.cbLabelLocation.SelectedItem.ToString().Trim().ToUpper())
                    {
                    case "BOTTOMLEFT": bar.LabelPosition = BarcodeLib.LabelPositions.BOTTOMLEFT; break;

                    case "BOTTOMRIGHT": bar.LabelPosition = BarcodeLib.LabelPositions.BOTTOMRIGHT; break;

                    case "TOPCENTER": bar.LabelPosition = BarcodeLib.LabelPositions.TOPCENTER; break;

                    case "TOPLEFT": bar.LabelPosition = BarcodeLib.LabelPositions.TOPLEFT; break;

                    case "TOPRIGHT": bar.LabelPosition = BarcodeLib.LabelPositions.TOPRIGHT; break;

                    default: bar.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; break;
                    }

                    //===== 此处执行编码 =====
                    gbxBarCoder.BackgroundImage = bar.Encode(type, this.txtContent.Text.Trim(), this.btnForeColor.BackColor, this.btnBackColor.BackColor, W, H);
                    //===================================

                    //显示编码耗时
                    this.lblEncodingTime.Text = "(" + Math.Round(bar.EncodingTime, 0, MidpointRounding.AwayFromZero).ToString() + "ms)";

                    txtEncoded.Text = bar.EncodedValue;

                    //读取动态计算的宽度/高度,因为用户感兴趣。
                    if (bar.BarWidth.HasValue)
                    {
                        txtWidth.Text = bar.Width.ToString();
                    }
                    if (bar.AspectRatio.HasValue)
                    {
                        txtHeight.Text = bar.Height.ToString();
                    }
                }//if

                //条形码图像重新定位到中间
                gbxBarCoder.Location = new Point((this.gbxBarCoder.Location.X + this.gbxBarCoder.Width / 2) - gbxBarCoder.Width / 2, (this.gbxBarCoder.Location.Y + this.gbxBarCoder.Height / 2) - gbxBarCoder.Height / 2);
            }
            catch (Exception ex)
            {
                TipHelper.TipMsg(this, $"{ex.Message}");
            }
        }