C# 实现条码图片自动生成功能
C# 实现条码图片自动生成功能
BarCodeControl,v 1.5.0.0
版权所有 (C) Cobainsoft 2005 - 2007
需要引用Barcode.dll组件,在Debug目录下,生成的条码效果图如下:
组合条码图片:
BarCodeControl,v 1.5.0.0
版权所有 (C) Cobainsoft 2005 - 2007
需要引用Barcode.dll组件,在Debug目录下,生成的条码效果图如下:
C# Code:
private void btnDO_Click(object sender, EventArgs e)
{
string barcode = "";
//打开生成条码窗体
Image img = frmBarcodeGenerator.Execute(out barcode);
if (img != null)
{
img.Save("c:\\ttt_.bmp", ImageFormat.Bmp); //存到临时文件
byte[] bs = this.GetImageBytes("c:\\ttt_.bmp");//转换为byte数组
DataRow newBarcode = (gridControl1.DataSource as DataTable).NewRow();
(gridControl1.DataSource as DataTable).Rows.Add(newBarcode);
newBarcode["Barcode"] = barcode;
newBarcode["BarcodeImage"] = bs;
gridView1.UpdateCurrentRow();
gridView1.FocusedColumn.Width = 1; //自动缩放
gridView1.FocusedColumn.Width -= 1;
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private void btnDO_Click(object sender, EventArgs e)
{
string barcode = "";
//打开生成条码窗体
Image img = frmBarcodeGenerator.Execute(out barcode);
if (img != null)
{
img.Save("c:\\ttt_.bmp", ImageFormat.Bmp); //存到临时文件
byte[] bs = this.GetImageBytes("c:\\ttt_.bmp");//转换为byte数组
DataRow newBarcode = (gridControl1.DataSource as DataTable).NewRow();
(gridControl1.DataSource as DataTable).Rows.Add(newBarcode);
newBarcode["Barcode"] = barcode;
newBarcode["BarcodeImage"] = bs;
gridView1.UpdateCurrentRow();
gridView1.FocusedColumn.Width = 1; //自动缩放
gridView1.FocusedColumn.Width -= 1;
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
组合条码图片:
C# Code:
private void PreviewKJ()
{
barcodeControl2.Data = textEdit16.Text; //给条码控制指定编号
label31.Visible = checkEdit1.Checked;
label32.Text = textEdit13.Text;
label35.Text = textEdit17.Text;
//创建白底条码空白图片
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pictureBox3.Width, pictureBox3.Height);
DrawBackgroundColor(bmp);
Rectangle rec = new Rectangle(barcodeControl2.Location, barcodeControl2.Size);
barcodeControl2.DrawToBitmap(bmp, rec); //将条码画到空白图片
rec = new Rectangle(label32.Location, label32.Size);
label32.DrawToBitmap(bmp, rec); //将附加信息画到空白图片
rec = new Rectangle(label35.Location, label35.Size);
label35.DrawToBitmap(bmp, rec);//将附加信息画到空白图片
if (checkEdit1.Checked)
{
rec = new Rectangle(label31.Location, label31.Size);
label31.DrawToBitmap(bmp, rec);//将附加信息画到空白图片
}
picOutput.Size = pictureBox3.Size;
picOutput.Image = bmp;
picOutput.Height = 10;
_retBarcode = textEdit16.Text;//条码编号
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private void PreviewKJ()
{
barcodeControl2.Data = textEdit16.Text; //给条码控制指定编号
label31.Visible = checkEdit1.Checked;
label32.Text = textEdit13.Text;
label35.Text = textEdit17.Text;
//创建白底条码空白图片
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pictureBox3.Width, pictureBox3.Height);
DrawBackgroundColor(bmp);
Rectangle rec = new Rectangle(barcodeControl2.Location, barcodeControl2.Size);
barcodeControl2.DrawToBitmap(bmp, rec); //将条码画到空白图片
rec = new Rectangle(label32.Location, label32.Size);
label32.DrawToBitmap(bmp, rec); //将附加信息画到空白图片
rec = new Rectangle(label35.Location, label35.Size);
label35.DrawToBitmap(bmp, rec);//将附加信息画到空白图片
if (checkEdit1.Checked)
{
rec = new Rectangle(label31.Location, label31.Size);
label31.DrawToBitmap(bmp, rec);//将附加信息画到空白图片
}
picOutput.Size = pictureBox3.Size;
picOutput.Image = bmp;
picOutput.Height = 10;
_retBarcode = textEdit16.Text;//条码编号
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网