예제 #1
0
        private void btnBatchPrint_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(tbBarCodeWidth.Text))
            {
                barCodeWidth = int.Parse(tbBarCodeWidth.Text);
            }
            if (!string.IsNullOrWhiteSpace(tbBarcodeHeight.Text))
            {
                barCodeHeight = int.Parse(tbBarcodeHeight.Text);
            }
            if (!string.IsNullOrWhiteSpace(tbBarCodeSpacing.Text))
            {
                barCodeSpacing = int.Parse(tbBarCodeSpacing.Text);
            }
            if (!string.IsNullOrWhiteSpace(tbFontSize.Text))
            {
                fontSize = int.Parse(tbFontSize.Text);
            }


            barCodeImages.Clear();
            printCounter = 0;
            if (lbBarCodes.Items.Count > 0)
            {
                foreach (string s in lbBarCodes.Items)
                {
                    barCodeImages.Add(ObjectOperator.CreateBarCode(s, barCodeWidth, barCodeHeight, true));
                }
                //PrintDocument batchPrintDocument = new PrintDocument();
                try
                {
                    batchPrintDocument.PrinterSettings.PrinterName = cbPrinters.SelectedItem.ToString();
                    //PageSetupDialog pageSetupDialog = new PageSetupDialog();
                    //pageSetupDialog.Document = batchPrintDocument;
                    //if (DialogResult.OK == pageSetupDialog.ShowDialog())
                    //{
                    //batchPrintDocument.PrintPage += BatchPrint;
                    PrintPreviewDialog ppd = new PrintPreviewDialog();
                    ppd.Document = batchPrintDocument;
                    ppd.ShowDialog();


                    //}
                }
                catch (Exception ePrint)
                {
                    MessageBox.Show($"打印失败:\r\n{ePrint})", "打印失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                //finally
                //{ batchPrintDocument.Dispose(); }
            }
            else
            {
                MessageBox.Show("无可打印数据");
            }
        }
예제 #2
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            string codeString = tbCodeString.Text;

            if (!string.IsNullOrWhiteSpace(codeString))
            {
                Bitmap barCodeImage = ObjectOperator.CreateBarCode(codeString, 300, 100);
                pictureBoxBarCode.Image = barCodeImage;
            }
        }