【发布时间】:2014-02-10 13:05:46
【问题描述】:
我有两个列表,一个是字符串,另一个是 PictureBox 类型。我想获取字符串类型列表的值并将其转换为条形码,然后将其保存到图片框类型的列表中。
我现在就是这样:
List<System.Windows.Forms.PictureBox> PictureBoxList = new List<System.Windows.Forms.PictureBox>();
List<string> SerialNumberList = new List<string>();
int SerialNumberStart = 0;
for(int i = 0; i < 10 ; i++)
{
SerialNumberStart++;
SerialNumberList.Add("S" + SerialNumberStart);
}
private void PrintButton_Click(object sender, EventArgs e)
{
for(int j =0 ; j < SerialNumberList.Count ; j++)
{
BarcodeLib.TYPE barcodetype1 = BarcodeLib.TYPE.CODE39;
BarcodeLib.Barcode bar1 = new BarcodeLib.Barcode();
bar1.IncludeLabel = true;
PictureBoxList[j].Image = bar1.Encode(barcodetype1 ,SerialNumberList[j]); // It gives me exception of Index out of range
PictureBoxList.Add(PictureBoxList[j]);
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
printDocument1.Print();
}
}
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap myBitmap1 = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(myBitmap1, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
e.Graphics.DrawImage(myBitmap1, 0, 0);
myBitmap1.Dispose();
}
我的第一个问题是如何将字符串转换为 PictureBox。 然后将 PictureBox 的每个项目转换为位图,然后打印所有位图,现在代码只打印一个条形码
【问题讨论】:
-
在
PrintButton_Click方法中,您使用j作为循环计数器变量,但在循环内的所有代码中使用i而不是j。错字还是...? -
抱歉编辑了我的代码@har07
标签: c# printing bitmap barcode picturebox