private void drawNodeBarcode(Graphics g, XmlNode source, PointF margin, Font defaultFont) { if (XmlFunc.getBoolAttribute(source, "Visible", true)) { string code = source.InnerText.Trim(); if (code.Length != 0) { PointF tf = this.getLocationAttribute(source); tf.X += margin.X; tf.Y += margin.Y; Color color = this.getFontColorAttribute(source); Color white = new Color(); white = Color.White; float num = float.Parse(XmlFunc.getStringAttribute(source, "ByteWidth", "12.00")); SizeF ef = this.getSizeAttribute(source); ef.Width = (num * SizeDef.PrintPixelPerDisplayPixel) * (code.Length + 2); DotNetBarcode barcode = new DotNetBarcode(DotNetBarcode.Types.Code39); using (Font font = this.getFontAttribute(source, defaultFont)) { barcode.FontName = font.Name; barcode.FontSize = font.Size; barcode.FontBold = font.Bold; barcode.FontItalic = font.Italic; barcode.FontColor = color; barcode.FontBackGroundColor = white; barcode.BarColor = color; barcode.BackGroundColor = white; barcode.WriteBar(code, tf.X, tf.Y, ef.Width, ef.Height, g); } } } }
void prtdoc_PrintPage(object sender, PrintPageEventArgs e) { if (_listCode != null) { if (_listCode.Count > 0 && _listType.Count > 0) { if (PageIndex == _listCode.Count) { PageIndex = 0; } Graphics g = e.Graphics; e.HasMorePages = false; //此处打开多页打印属性 bc.WriteBar(_listCode[PageIndex], 100, 0, 140, 140, g); float titleWidth = g.MeasureString(_listCode[PageIndex], FontContent).Width; g.DrawString(_listType[PageIndex], FontContent, Brushes.Black, new PointF(110 + (140 - titleWidth) / 2, 100)); //在左上角0,0的位置打印图像 if (PageIndex == _listCode.Count - 1) //共打印10张 { e.HasMorePages = false; //关掉多页打印属性 } PageIndex++; //il是一个计数器,即页数 } } }
void prtdoc_PrintPage(object sender, PrintPageEventArgs e) { if (_listCode != null) { if (_listCode.Count > 0) { if (PageIndex == _listCode.Count) { PageIndex = 0; } Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.HasMorePages = true; //此处打开多页打印属性 int paddingLeft = 80, paddingTop = 30, scale = 100; bc.WriteBar(_listCode[PageIndex], paddingLeft, paddingTop, scale, scale, g); float titleWidth = g.MeasureString(_listCode[PageIndex], FontContent).Width; g.DrawString(_listCode[PageIndex], FontContent, Brushes.Black, new PointF((scale - titleWidth) / 2 + paddingLeft - 5, scale + 5)); //在左上角0,0的位置打印图像 if (PageIndex == _listCode.Count - 1) //共打印10张 { e.HasMorePages = false; //关掉多页打印属性 } PageIndex++; //il是一个计数器,即页数 } } }
private void TextBox1_TextChanged(object sender, EventArgs e) { int num2; int num3; object obj; try { IL_01: int num = 1; DotNetBarcode dotNetBarcode = new DotNetBarcode(); IL_09: num = 2; dotNetBarcode.Type = DotNetBarcode.Types.QRCode; IL_12: num = 3; dotNetBarcode.PrintCheckDigitChar = true; IL_1B: ProjectData.ClearProjectError(); num2 = -2; IL_23: num = 5; dotNetBarcode.WriteBar(this.TextBox1.Text, 0f, 0f, (float)this.SplitContainer1.Panel2.Width, (float)this.SplitContainer1.Panel2.Height, this.SplitContainer1.Panel2.CreateGraphics()); IL_72: goto IL_D7; IL_74: goto IL_E1; IL_76: num3 = num; if (num2 <= -2) { goto IL_8D; } @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num2); goto IL_B5; IL_8D: int num4 = num3 + 1; num3 = 0; @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num4); IL_B5: goto IL_E1; } catch when(endfilter(obj is Exception & num2 != 0 & num3 == 0)) { Exception ex = (Exception)obj2; goto IL_76; } IL_D7: if (num3 != 0) { ProjectData.ClearProjectError(); } return; IL_E1: throw ProjectData.CreateProjectError(-2146828237); }
private void ptQRCode_Paint(object sender, PaintEventArgs e) { e.Graphics.FillRectangle(Brushes.White, new Rectangle() { X = 0, Y = 0, Width = 251, Height = 126 }); bc.WriteBar(textBox4.Text.Trim(), 200, 50, 80, 80, e.Graphics); SolidBrush b1 = new SolidBrush(Color.Black);//定义单色画刷 e.Graphics.DrawString("商品名:" + textBox3.Text, new Font("宋体", 11), b1, new PointF(0, 0)); e.Graphics.DrawString("生产日期:" + textBox5.Text, new Font("宋体", 11), b1, new PointF(0, 20)); e.Graphics.DrawString("生产厂家:" + textBox6.Text, new Font("宋体", 11), b1, new PointF(0, 40)); e.Graphics.DrawString("保质期:" + textBox8.Text, new Font("宋体", 11), b1, new PointF(0, 60)); e.Graphics.DrawString("库存:" + textBox11.Text, new Font("宋体", 9), b1, new PointF(190, 0)); }
private void btnPrint_Click(object sender, RoutedEventArgs e) { if (dataTable == null || dataTable.Rows.Count <= 0) { MessageBox.Show("信息有误,无法打印!"); return; } //创建二维码 Bitmap b = new Bitmap(200, 325); Graphics g = Graphics.FromImage(b); DotNetBarcode bc = new DotNetBarcode(); bc.Type = DotNetBarcode.Types.QRCode; string code = BaseData.stationID.ToString() + " "; code += dataTable.Rows[0]["TruckNo"].ToString().Trim().Substring(1) + " "; code += DateTime.Parse(dataTable.Rows[0]["PushTime"].ToString()).ToString("yyyy-MM-dd,HH:mm:ss") + " "; code += dataTable.Rows[0]["Type1"].ToString().Trim(); string pstr = "" + BaseData.stationName.Replace(" ", "") + "清洁站管理系统\n"; pstr += "车牌号:" + dataTable.Rows[0]["TruckNo"].ToString().Trim() + "\n"; pstr += "出发时间:" + DateTime.Parse(dataTable.Rows[0]["PushTime"].ToString()).ToString("yy-MM-dd,HH:mm:ss") + "\n"; pstr += "垃圾类型:" + dataTable.Rows[0]["Type1"].ToString().Trim()+"\n"; pstr += "二维码:\n"; System.Drawing.Pen p = new System.Drawing.Pen(new SolidBrush(System.Drawing.Color.Black)); p.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; p.DashPattern = new float[] {3,5 }; g.DrawLine(p, 0, 0, 200, 0); g.DrawString(pstr, new Font("宋体", 11), new SolidBrush(System.Drawing.Color.Black), 0, 20); bc.WriteBar(code, 0, 120, 200, 320, g); g.DrawLine(p, 0, 320, 200, 320); b.Save("test.jpg"); printImage = b; //打印信息 System.Windows.Forms.PrintDialog pDialog = new System.Windows.Forms.PrintDialog(); pDialog.Document = new PrintDocument(); pDialog.Document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(document_PrintPage); pDialog.Document.Print(); }
// Sub procedure: Show barcode graphics to the decoration pannel private void pnlBarcode_Paint(object sender, PaintEventArgs e) { DotNetBarcode barCode = new DotNetBarcode(); string barcodeNumber; Single x1; Single y1; Single x2; Single y2; x1 = 0; y1 = 0; x2 = pnlBarcode.Size.Width; y2 = pnlBarcode.Size.Height; barcodeNumber = txtBoxIdFrom.Text; barCode.Type = DotNetBarcode.Types.Jan13; if (barcodeNumber != String.Empty) { barCode.WriteBar(barcodeNumber, x1, y1, x2, y2, e.Graphics); } }
/// <summary> /// 生成二维码 DotNetBar自带插件 /// </summary> /// <param name="data"></param> private Image QRCodeBar(string data) { DotNetBarcode bc = new DotNetBarcode(); bc.Type = DotNetBarcode.Types.QRCode; bc.PrintCheckDigitChar = true; bc.PrintChar = true; bc.PrintCheckDigitChar = true; Bitmap btm = new Bitmap(this.picEncode.Width, this.picEncode.Height); Graphics g = Graphics.FromImage(btm); bc.WriteBar(data, 0, 0, this.picEncode.Width + 5, this.picEncode.Width + 5, g); Font FontContent = new Font("宋体", 16, FontStyle.Bold); float titleWidth = g.MeasureString(data, FontContent).Width; g.DrawString(data, FontContent, Brushes.Black, new PointF((this.picEncode.Width - titleWidth) / 2, this.picEncode.Height - 25)); MemoryStream ms = new MemoryStream(); btm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); Image image = Image.FromStream(ms); return(image); }
private void ptQRCode_Paint(object sender, PaintEventArgs e) { bc.WriteBar(this.txtContent.Text.Trim(), 0, 0, this.ptQRCode.Width, this.ptQRCode.Height, e.Graphics); }
private void panel1_Paint(object sender, PaintEventArgs e) { bc.WriteBar(this.textBox1.Text, 0, 0, this.panel1.Width, this.panel1.Height, e.Graphics); }