private void cmbPart_Leave(object sender, EventArgs e) { bool someViablePartWasSelected = (cmbPart.SelectedItem != null); this.buttonGenerate.Enabled = !(someViablePartWasSelected) && cmbPart.Text != ""; if (someViablePartWasSelected) { // show barcode for part BarcodePartDataClass partToResolve = cmbPart.SelectedItem as BarcodePartDataClass; this.textBoxBarcode.Text = partToResolve.BarcodeRaw; // generate here barcode and show it BarcodeLib.TYPE type = TYPE.EAN13; // maybe, add input field with additional symbologies to select? int W = pictureBoxBarCode.Width - 10; int H = pictureBoxBarCode.Height - 10; pictureBoxBarCode.BackgroundImage = b.Encode(type, this.textBoxBarcode.Text.Trim(), Color.Black, Color.White, W, H); } }
private void PrintDoc_PrintPage(object sender, PrintPageEventArgs e) { if (currentPagePrinting <= maxPagePrinting) { // blur go away! e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; e.Graphics.PixelOffsetMode = PixelOffsetMode.None; // or PixelOffsetMode.Half Font printFont = new Font("Courier New", 7); e.Graphics.DrawString(itemsToShow[currentPagePrinting - 1].BarcodeMachine, printFont, Brushes.Black, 1, 1); e.Graphics.DrawString(itemsToShow[currentPagePrinting - 1].BarcodeCustomer, printFont, Brushes.Black, 1, 1 + printFont.Height); // clojure and lambda BarcodePartDataClass bpdc = handlingClassRef.allPartsList.Find((BarcodePartDataClass in_bcode) => { return(in_bcode.ID == itemsToShow[currentPagePrinting - 1].barcodePartID); }); //draw barcode Barcode b = new Barcode(); b.IncludeLabel = false; // well, the label text is blurry. To overcome this we need to modify barcodelib b.Alignment = AlignmentPositions.LEFT; float dpix = e.Graphics.DpiX; float dpiy = e.Graphics.DpiY; int dpiXPrinter = e.PageSettings.PrinterResolution.X; int dpiYPrinter = e.PageSettings.PrinterResolution.Y; // https://www.pixelcalculator.com/ int W = (int)Math.Round(96 * handlingClassRef.newconfig.labelParameters.barcodeLabelBCodeWidth / 25.4); int H = (int)Math.Round(96 * handlingClassRef.newconfig.labelParameters.barcodeLabelBCodeHeight / 25.4); Image bcodeImg = b.Encode(TYPE.EAN13, bpdc.BarcodeRaw, Color.Black, Color.White, W, H); e.Graphics.DrawImageUnscaled(bcodeImg, 40, 1 + 2 * printFont.Height); RectangleF fff = e.Graphics.ClipBounds; e.Graphics.FillRectangle(Brushes.White, 40, 1 + printFont.Height + H, fff.Width - 1, printFont.Height + 2); e.Graphics.DrawString("T" + itemsToShow[currentPagePrinting - 1].BarcodeTruck.ToString("D3") + " " + bpdc.BarcodeRaw, printFont, Brushes.Black, 1, 1 + printFont.Height + H + 1); e.Graphics.DrawString(itemsToShow[currentPagePrinting - 1].BarcodePart, printFont, Brushes.Black, 1, 1 + 2 * printFont.Height + H); currentPagePrinting++; e.HasMorePages = (currentPagePrinting <= maxPagePrinting); } else { e.HasMorePages = false; // risk of infinite cycle currentPagePrinting = 1; } }