如何添加名单,LT值;字符串>到List<&图片框GT;编码后到酒吧在C#code [英] How to Add the values of List<string> into the List<PictureBox> after encoding it to Barcode in c#

查看:219
本文介绍了如何添加名单,LT值;字符串>到List<&图片框GT;编码后到酒吧在C#code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列出一个是字符串,而另一个是图片框型。我想利用字符串类型和其转换成律师code列表的值,然后将其保存到图片框类型的列表。

我现在做这样的权利:

 列表< System.Windows.Forms.PictureBox> PictureBoxList =新的List< System.Windows.Forms.PictureBox>();
清单<串GT; SerialNumberList =新的List<串GT;();
INT SerialNumberStart = 0;的for(int i = 0;我小于10;我++)
{
    SerialNumberStart ++;
    SerialNumberList.Add(S+ SerialNumberStart);
}私人无效PrintButton_Click(对象发件人,EventArgs的发送)
{
   对于(INT J = 0; J< SerialNumberList.Count; J ++)
   {
    酒吧codeLib.TYPE酒吧codetype1 =酒吧codeLib.TYPE code39。
    酒吧codeLib.Bar code BAR1 =新的酒吧codeLib.Bar code();
    bar1.IncludeLabel = TRUE;
    PictureBoxList [J] =图像配bar1.En code(巴codetype1,SerialNumberList [J]); //它给我指标异常超出范围
    PictureBoxList.Add(PictureBoxList [J]);
    printDocument1.PrintPage + =新System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
    printDocument1.Print();
   }
}私人无效PrintDocument_PrintPage(对象发件人,System.Drawing.Printing.PrintPageEventArgs E)
{
  位图myBitmap1 =新位图(pictureBox1.Width,pictureBox1.Height);
  pictureBox1.DrawToBitmap(myBitmap1,新的Rectangle(0,0,pictureBox1.Width,pictureBox1.Height));
  e.Graphics.DrawImage(myBitmap1,0,0);
  myBitmap1.Dispose();
}

我的第一个问题是,我如何可以转换字符串到PictureBox。
然后将图片框的每个项目转换成位图,然后打印所有位图现在的code只打印一间酒吧code


解决方案

你想这样的..正确的?看到这是在3of9的这串S1​​253551重新presentaion和纯文本,最后作为图像正确的?

 公众形象stringToImage(字符串inputString)
    {
        字符串文本= inputString.Trim();        BMP位图=新位图(1,1);        //设置输出图像的字体样式
        字体的字体=新Font(自由9 3,25,FontStyle.Regular,GraphicsUnit.Pixel);
        字体font2 =新的字体(宋体,15,FontStyle.Regular,GraphicsUnit.Pixel);        显卡显卡= Graphics.FromImage(BMP);        INT宽度=(INT)graphics.MeasureString(文字,字体).WIDTH;
        INT高度=(int)的graphics.MeasureString(文字,字体).Height;        INT身高2 =(int)的graphics.MeasureString(文字,font2).Height;        BMP =新图(BMP,新的大小(宽度,高度+身高2));
        显卡= Graphics.FromImage(BMP);        //指定图像的背景色
        graphics.Clear(Color.Cyan);
        graphics.Smoothi​​ngMode = Smoothi​​ngMode.AntiAlias​​;
        graphics.TextRenderingHint = TextRenderingHint.AntiAlias​​;        //指定图像的文字,字体,文本颜色,X位置和Y位置
        graphics.DrawString(文本,字体,新SolidBrush(Color.Black),0,0);
        graphics.DrawString(文字,font2,新SolidBrush(Color.Black),0,高度);        graphics.Flush();
        graphics.Dispose();        //如果你想保存图像取消对下面一行。
        //bmp.Save(@\"d:\\myimage.jpg,ImageFormat.Jpeg);        返回BMP;
    }

记住,你必须已经安装了免费9 3字型。

您传递字符串S1253551,它产生的吧code,并在底部添加纯文本,最后返回它的形象。

其工作code我在我的最终审判。请享用。 :)

下载从这里下载

I have two List one is of string and the other is of PictureBox type. I want to take the values of List of type string and the convert it into the Barcode then save it to the List of type PictureBox.

I am doing it like this right now:

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();
}

My first question is that How can I convert the string into the PictureBox. And then converting each item of the PictureBox to the Bitmap and then printing all of the bitmaps now the code only Prints one barcode

解决方案

you want like this.. right?? see this is the representaion of the this string "S1253551" in 3of9 and plain text and finally as image right??

    public Image stringToImage(string inputString)
    { 
        string text = inputString.Trim();

        Bitmap bmp = new Bitmap(1, 1);

        //Set the font style of output image
        Font font = new Font("Free 3 of 9", 25, FontStyle.Regular, GraphicsUnit.Pixel);
        Font font2 = new Font("Arial", 15, FontStyle.Regular, GraphicsUnit.Pixel);

        Graphics graphics = Graphics.FromImage(bmp);

        int width = (int)graphics.MeasureString(text, font).Width;
        int height = (int)graphics.MeasureString(text, font).Height;

        int height2 = (int)graphics.MeasureString(text, font2).Height;

        bmp = new Bitmap(bmp, new Size(width, height+height2));
        graphics = Graphics.FromImage(bmp);



        //Specify the background color of the image
        graphics.Clear(Color.Cyan);
        graphics.SmoothingMode = SmoothingMode.AntiAlias;
        graphics.TextRenderingHint = TextRenderingHint.AntiAlias;



        //Specify the text, font, Text Color, X position and Y position of the image
        graphics.DrawString(text, font, new SolidBrush(Color.Black), 0, 0);
        graphics.DrawString(text, font2, new SolidBrush(Color.Black), 0, height);

        graphics.Flush();
        graphics.Dispose();

        //if you want to save the image  uncomment the below line.
        //bmp.Save(@"d:\myimage.jpg", ImageFormat.Jpeg);

        return bmp;
    }

Remember you must have installed "free 3 of 9" font.

you pass the string "S1253551" and it generate the barcode and add the plain text at bottom and finally return it as image.

Its working code i have tried at my end. Enjoy. :)

Download the working code from here Download

这篇关于如何添加名单,LT值;字符串&GT;到List&LT;&图片框GT;编码后到酒吧在C#code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆