//输入ID
        private void button1_Click(object sender, EventArgs e)
        {
            //AddLabel("area"+index);
            //index++;

            IDlogin ID = new IDlogin();
            ID.GetForm(this);
            ID.ShowDialog();
            Prm1 = GetAreaExcel(id);
            if (Prm1 != null)
            {
                Prm = GetModelExcel();

                for (int i = 0; i < Prm.Length / 5; i++)
                {
                    string a=Prm[i, 0].Trim().Substring(4);
                    int.Parse(a);
                    Prm[i, 0] = Prm[i, 0].Replace(Prm[i, 0],Prm1[int.Parse(Prm[i, 0].Trim().Substring(4))-1]);
                }

                Image im = new Bitmap(panel1.Width, panel1.Height);
                Graphics g = Graphics.FromImage(im);

                for (int i = 0; i < Prm.Length / 5; i++)
                {
                    Font font = new Font(Prm[i, 4], int.Parse(Prm[i, 3]), FontStyle.Bold);
                    g.DrawString(Prm[i, 0], font, Brushes.Black, (float.Parse(Prm[i, 1]) - 3) * 3F, (60 - float.Parse(Prm[i, 2]) - 5) * 4F);
                }

                Barcode bar = new Barcode();
                g.ScaleTransform(1, 0.54f);
                g.DrawImage(bar.GetBarCode(Prm1[2]), 300, 250);

                //g.ScaleTransform(1, 1.9f);

                panel1.BackgroundImageLayout = ImageLayout.Stretch;
                panel1.BackgroundImage = im;
            }
            else MessageBox.Show("id号输入不正确!");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (Prm1 != null)
            {
                Prm = GetModelExcel();

                for (int i = 0; i < Prm.Length / 5; i++)
                {
                    string a = Prm[i, 0].Trim().Substring(4);
                    int.Parse(a);
                    Prm[i, 0] = Prm[i, 0].Replace(Prm[i, 0], Prm1[int.Parse(Prm[i, 0].Trim().Substring(4)) - 1]);
                }

                Image im = new Bitmap(panel1.Width, panel1.Height);
                Graphics g = Graphics.FromImage(im);

                for (int i = 0; i < Prm.Length / 5; i++)
                {
                    Font font = new Font(Prm[i, 4], int.Parse(Prm[i, 3]), FontStyle.Bold);
                    g.DrawString(Prm[i, 0], font, Brushes.Black, (float.Parse(Prm[i, 1]) - 3) * 3F, (60 - float.Parse(Prm[i, 2]) - 5) * 4F);
                }
                using (OpenFileDialog dlg = new OpenFileDialog())
                {
                    dlg.Title = "Insert picture";
                    dlg.DefaultExt = "jpg";
                    dlg.Filter = "Bitmap Files|*.bmp|JPEG Files|*.jpg|GIF Files|*.gif|All files|*.*";
                    dlg.FilterIndex = 1;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            CEImagePath = dlg.FileName;
                            Image img = Image.FromFile(CEImagePath);
                            g.DrawImage(img, new Rectangle(4, 200, 30, 30));
                            //g.DrawImage(img, 300, 250);
                            //Clipboard.SetDataObject(img);
                            //DataFormats.Format df = DataFormats.GetFormat(DataFormats.Bitmap);
                        }
                        catch
                        {
                            MessageBox.Show("Unable to insert image.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }

                Barcode bar = new Barcode();
                g.ScaleTransform(1, 0.54f);
                g.DrawImage(bar.GetBarCode(Prm1[2]), 300, 250);
                //g.ScaleTransform(1, 1.9f);

                panel1.BackgroundImageLayout = ImageLayout.Stretch;
                panel1.BackgroundImage = im;
            }

            //panel1.Controls.Remove(lab);
        }
        private void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            string[] Prm1;
            //string[,] Prm;
            //Prm = GetModelExcel();
            Prm1 = GetAreaExcel(id);

            for (int i = 0; i < Prm.Length / 5; i++)
            {
                Font font = new Font(Prm[i, 4], int.Parse(Prm[i, 3]), FontStyle.Bold);
                e.Graphics.DrawString(Prm[i, 0], font, Brushes.Black, (float.Parse(Prm[i, 1]) - 0) * 3F, (60 - float.Parse(Prm[i, 2]) - 5) * 4F);
            }
            if (CEImagePath != null)
            {
                Image img = Image.FromFile(CEImagePath);
                e.Graphics.DrawImage(img, new Rectangle(18, 175, 40, 40));
            }

            Barcode bar = new Barcode();
            e.Graphics.ScaleTransform(1f, 0.51f);
            e.Graphics.DrawImage(bar.GetBarCode(Prm1[2]), 300, 250);//270.0F, 220.0F);
            //e.Graphics.DrawImage(bar.GetBarCode(Prm1[2]), 0, 30);
            //e.Graphics.ScaleTransform(1f, 1.9f);

            //e.Graphics.ScaleTransform(0.5f, 1.9f);
            //Code39 _Code39 = new Code39();
            //_Code39.Height = 120;
            //_Code39.Magnify = 1;
            //_Code39.ViewFont = new Font("宋体", 20);
            //e.Graphics.ScaleTransform(1f, 0.35f);
            //e.Graphics.DrawImage(RotateImg(_Code39.GetCodeImage(Prm1[2], Code39.Code39Model.Code39Normal, true), 90), 200.0F, 150.0F);

            //CSharpCode39 code = new CSharpCode39();
            //e.Graphics.DrawImage(code.getBitmapImage(12), 200.0F, 150.0F);
        }
        private void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            string[] Prm;
            string[] Prm1;
            r = GetCurrentRichTextBox();
            Prm = GetExcel(id);
            Prm1 = GetExcel("area2");

            /*如果需要改变自己 可以在new Font(new FontFamily("黑体"),11)中的“黑体”改成自己要的字体就行了,黑体 后面的数字代表字体的大小
             System.Drawing.Brushes.Blue , 170, 10 中的 System.Drawing.Brushes.Blue 为颜色,后面的为输出的位置 ,第一个10是左边距,第二个35是上边距*/
            //e.Graphics.DrawString(GetCurrentRichTextBox().Text, new Font(new FontFamily("Arial"), 11), Brushes.Black, 0, 0);
            //for (int j = Prm1.Length-1; j >=0; j--)
            //{
            //    if (r.Text.Contains(Prm1[j]))
            //    {
            //        r.Text = r.Text.Replace(Prm1[j], Prm[j]);
            //    }
            //}
            //e.Graphics.DrawString(r.Text, r.SelectionFont, Brushes.Black, 0, 0);

            Barcode bar = new Barcode();
            e.Graphics.ScaleTransform(1, 0.5f);
            e.Graphics.DrawImage(RotateImg(bar.GetBarCode(Prm[2]), 90), 275.0F, 238.0F);

            e.Graphics.ScaleTransform(1, 2);
            Font font1 = new Font("Arial Narrow", 11);
            Font font2 = new Font("Arial Narrow", 12);
            Font font3 = new Font("Arial Narrow", 8);
            int xcurrent = 315;
            int ycurrent = 236;
            for (int j = Prm1.Length - 1; j >= 0; j--)
            {
                if (r.Text.Contains(Prm1[j]))
                {
                    switch (j)
                    {
                        case 0:
                            e.Graphics.DrawString(Prm[0], font2, Brushes.Black, (float)1 / (float)80 * xcurrent, (float)15 / (float)60 * ycurrent);
                            break;
                        case 1:
                            e.Graphics.DrawString(Prm[1], font2, Brushes.Black, (float)((float)16 / (float)80)* xcurrent, (float)((float)15 / (float)60) * ycurrent);
                            break;
                        case 2:
                            e.Graphics.DrawString(Prm[2], font3, Brushes.Black, (float)59 / (float)80 * xcurrent, (float)54.5 / (float)60 * ycurrent);
                            break;
                        case 3:
                            e.Graphics.DrawString(Prm[3], font1, Brushes.Black, (float)1 / 80 * xcurrent, (float)0 / 60 * ycurrent);
                            break;
                        case 4:
                            e.Graphics.DrawString(Prm[4], font1, Brushes.Black, (float)1 / 80 * xcurrent, (float)((float)5 / (float)60) * ycurrent);
                            break;
                        case 5:
                            e.Graphics.DrawString(Prm[5], font1, Brushes.Black, (float)1 / 80 * xcurrent, (float)10 / 60 * ycurrent);
                            break;
                        case 6:
                            e.Graphics.DrawString(Prm[6], font2, Brushes.Black, (float)1 / 80 * xcurrent, (float)21 / 60 * ycurrent);
                            break;
                        case 7:
                            e.Graphics.DrawString(Prm[7], font2, Brushes.Black, (float)12 / 80 * xcurrent, (float)21 / 60 * ycurrent);
                            break;
                        case 8:
                            e.Graphics.DrawString(Prm[8], font2, Brushes.Black, (float)28 / 80 * xcurrent, (float)27 / 60 * ycurrent);
                            break;
                        case 9:
                            e.Graphics.DrawString(Prm[9], font2, Brushes.Black, (float)1 / 80 * xcurrent, (float)31.5 / 60 * ycurrent);
                            break;
                        case 10:
                            e.Graphics.DrawString(Prm[10], font2, Brushes.Black, (float)15 / (float)80 * xcurrent, (float)31.5 / 60 * ycurrent);
                            break;
                        case 11:
                            e.Graphics.DrawString(Prm[11], font2, Brushes.Black, (float)28 / 80 * xcurrent, (float)37 / 60 * ycurrent);
                            break;
                        case 12:
                            e.Graphics.DrawString(Prm[12], font2, Brushes.Black, (float)((float)28 / (float)80) * xcurrent, (float)41.5 / 60 * ycurrent);
                            break;
                        case 13:
                            e.Graphics.DrawString(Prm[13], font2, Brushes.Black, (float)28 / 80 * xcurrent, (float)46 / 60 * ycurrent);
                            break;
                        case 14:
                            //e.Graphics.DrawString(r.Lines[14], font2, Brushes.Black, 3 / 80 * xcurrent, 0);
                            break;
                        case 15:
                            e.Graphics.DrawString(Prm[15], font2, Brushes.Black, (float)28 / 80 * xcurrent, (float)48.5 / 60 * ycurrent);
                            break;
                        case 16:
                            //e.Graphics.DrawString(r.Lines[16], font2, Brushes.Black, 3 / 80 * xcurrent, 0);
                            break;
                        case 17:
                            //e.Graphics.DrawString(r.Lines[17], font2, Brushes.Black, 3 / 80 * xcurrent, 0);
                            break;
                        default:
                            MessageBox.Show("area缺失");
                            break;
                    }
                    //r.Text = r.Text.Replace(Prm1[j], Prm[j]);
                }
            }

            for (int j = Prm1.Length - 1; j >= 0; j--)
            {
                if (r.Text.Contains(Prm1[j]))
                {
                    r.Text = r.Text.Replace(Prm1[j], Prm[j]);
                }
            }

            //Barcode bar = new Barcode();
            //e.Graphics.ScaleTransform(1, 0.5f);
            //e.Graphics.DrawImage(RotateImg(bar.GetBarCode(Prm[2]), 90), 275.0F, 238.0F);

            //Linear code39 = new Linear();
            //// Barcode data to encode
            //code39.Data = Prm[2];
            //code39.Type = BarcodeType.CODE39;
            ////code39.AddCheckSum = true;
            //code39.ShowText = false;
            //// The space between 2 characters in code 39; This a multiple of X; The default is 1.
            //code39.I = 1.0f;
            //// Wide/narrow ratio, 2.0 - 3.0 inclusive, default is 2.
            //code39.N = 2.0f;
            //// If true, display a * in the beginning and end of barcode text
            //code39.ShowStartStopInText = false;

            ///*
            //* Barcode Image Related Settings
            //*/
            //// Unit of meature for all size related setting in the library.
            ////code39.UOM = UnitOfMeasure.PIXEL;
            //// Bar module width (X), default is 1 pixel;
            //code39.X = 1;
            //// Bar module height (Y), default is 60 pixel;
            //code39.Y = 60;

            //// Image resolution in dpi, default is 72 dpi.
            //code39.Resolution = 50;

            //code39.Format = ImageFormat.Emf;

            ////e.Graphics.TranslateTransform(100, 100);
            ////e.Graphics.TranslateTransform(0.0F, -320.0F); // 平移
            ////e.Graphics.ScaleTransform(0.65f, 1);
            ////e.Graphics.RotateTransform(90.0F);
            ////e.Graphics.ScaleTransform(1, 0.67f);
            //e.Graphics.ScaleTransform(0.5f, 1);
            ////e.Graphics.DrawImage(DrawImg39(new EnCodeString().code39(Prm[2])), 200.0F, 200.0F);
            ////e.Graphics.DrawImage(RotateImg(code39.drawBarcode(), 90), 287.0F, 190.0F);
            //e.Graphics.DrawImage(code39.drawBarcode(), 200.0F, 200.0F);
        }