private void myPrintDocument2_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //set font
            Font printFont  = new Font("Code 128", 22);
            Font printFont2 = new Font("Arial", 6);
            Font printFont3 = new Font("Arial", 5);

            //set the bar-code width
            Matrix m = new Matrix();

            m.Scale(1F, 0.4F); //0.7 times height than original height

            //begin scale the bar-code width
            e.Graphics.Transform = m;
            string textBoxBarcode128 = BarcodeConverter128.StringToBarcode(textBoxBarcode.Text);

            e.Graphics.DrawString(textBoxBarcode128, printFont, System.Drawing.Brushes.Black, 2, 2, new StringFormat());
            //reset the font to regular width
            e.Graphics.ResetTransform();

            e.Graphics.DrawString(textBoxBarcode.Text, printFont2, System.Drawing.Brushes.Black, 45, 13, new StringFormat());

            e.Graphics.DrawString(textBoxPON.Text, printFont3, System.Drawing.Brushes.Black, 5, 22, new StringFormat());
            e.Graphics.DrawString(textBoxPN.Text, printFont3, System.Drawing.Brushes.Black, 113, 22, new StringFormat());
            //e.Graphics.DrawString(DateTime.Now.ToString("MMM dd,yyyy"), printFont2, System.Drawing.Brushes.Black, 175, 20, new StringFormat());
        }
Example #2
0
        public static string StringToBarcode(string value)
        {
            bool   flag1 = true;
            bool   flag2 = true;
            string str   = string.Empty;

            if (value.Length > 0)
            {
                for (int startIndex = 0; startIndex < value.Length; ++startIndex)
                {
                    int num = (int)char.Parse(value.Substring(startIndex, 1));
                    if (num < 32 || num > 126)
                    {
                        flag2 = false;
                        break;
                    }
                }
                if (flag2)
                {
                    int num1 = 0;
                    while (num1 < value.Length)
                    {
                        if (flag1)
                        {
                            int MinCharPos = num1 == 0 || num1 + 4 == value.Length ? 4 : 6;
                            if (BarcodeConverter128.IsNumber(value, num1, MinCharPos) < 0)
                            {
                                str   = num1 != 0 ? str + 'Ç'.ToString() : 'Í'.ToString();
                                flag1 = false;
                            }
                            else if (num1 == 0)
                            {
                                str = 'Ì'.ToString();
                            }
                        }
                        if (!flag1)
                        {
                            int MinCharPos = 2;
                            if (BarcodeConverter128.IsNumber(value, num1, MinCharPos) < 0)
                            {
                                int num2 = int.Parse(value.Substring(num1, 2));
                                int num3 = num2 < 95 ? num2 + 32 : num2 + 100;
                                str  += ((char)num3).ToString();
                                num1 += 2;
                            }
                            else
                            {
                                str  += 'È'.ToString();
                                flag1 = true;
                            }
                        }
                        if (flag1)
                        {
                            str += value.Substring(num1, 1);
                            ++num1;
                        }
                    }
                    int num4 = 0;
                    for (int startIndex = 0; startIndex < str.Length; ++startIndex)
                    {
                        int num2 = (int)char.Parse(str.Substring(startIndex, 1));
                        int num3 = num2 < (int)sbyte.MaxValue ? num2 - 32 : num2 - 100;
                        num4 = startIndex != 0 ? (num4 + startIndex * num3) % 103 : num3;
                    }
                    int num5 = num4 < 95 ? num4 + 32 : num4 + 100;
                    str = str + ((char)num5).ToString() + 'Î'.ToString();
                }
            }
            return(str);
        }