コード例 #1
0
        private void Form_previewreport_Load(object sender, EventArgs e)
        {
            try
            {
                Type type = panel1.GetType();
                System.Reflection.PropertyInfo pi = type.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                pi.SetValue(panel1, true, null);

                panel1.Controls.Clear();
                BarcodeLib.MyBarCodeControl barctrl;

                int x = 40;
                int y = 40;
                //tableLayoutPanel1.RowCount = RowCount;
                for (int i = 0; i < datadt.Rows.Count; i++)
                {
                    for (int j = 0; j < ColumnCount; j++)
                    {
                        //barctrl = new Cobainsoft.Windows.Forms.BarcodeControl();
                        barctrl = new BarcodeLib.MyBarCodeControl();
                        //barctrl.ResetProperties();
                        barctrl.CodeStyle  = BarcodeLib.TYPE.CODE128;
                        barctrl.BarCode    = datadt.Rows[i]["tjbh"].ToString().Trim();
                        barctrl.FooterText = datadt.Rows[i]["xm"].ToString().Trim() + "  " + datadt.Rows[i]["xb"].ToString().Trim() + "  " + datadt.Rows[i]["nl"].ToString().Trim();
                        barctrl.HeadText   = datadt.Rows[i]["tjbh"].ToString().Trim();
                        barctrl.ShowFooter = true;
                        barctrl.ShowHeader = true;
                        barctrl.Name       = datadt.Rows[i]["tjbh"].ToString().Trim();
                        //barctrl.AddOnCaption = null;
                        //barctrl.AddOnData = "";
                        //barctrl.AddOnTextPosition = Cobainsoft.Windows.Forms.BarcodeTextPosition.Below;
                        //barctrl.BackColor = System.Drawing.Color.White;
                        //barctrl.BarcodeType = Cobainsoft.Windows.Forms.BarcodeType.CODE128A;

                        //barctrl.CopyRight = "";
                        //barctrl.Caption = datadt.Rows[i]["xm"].ToString().Trim() + "  " + datadt.Rows[i]["xb"].ToString().Trim() + "  " + datadt.Rows[i]["nl"].ToString().Trim();
                        //barctrl.Data = datadt.Rows[i]["tjbh"].ToString().Trim();

                        Invalidate();
                        //barcodeCtrl.CopyRight = datadt.Rows[i]["tjbh"].ToString().Trim();
                        //barcodeCtrl.Invalidate();

                        barctrl.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                        // barctrl.ForeColor = System.Drawing.Color.Black;
                        //barctrl.HorizontalAlignment = Cobainsoft.Windows.Forms.BarcodeHorizontalAlignment.Center;
                        //barctrl.InvalidDataAction = Cobainsoft.Windows.Forms.InvalidDataAction.DisplayInvalid;
                        //barctrl.LowerTopTextBy = 0F;
                        //barctrl.RaiseBottomTextBy = 0F;
                        //barctrl.ShowCode39StartStop = false;
                        barctrl.Size = new Size(280, 90);

                        barctrl.Location = new Point(x + (200 * j), y + (110 * i));

                        // barctrl.CopyRight = datadt.Rows[i]["tjbh"].ToString().Trim();
                        panel1.Controls.Add(barctrl);
                        //panel1.Update();
                        //MessageBox.Show(barctrl.CopyRight);
                    }
                }

                //foreach (Control c in panel1.Controls)
                //{
                //    Cobainsoft.Windows.Forms.BarcodeControl c1 = c as  Cobainsoft.Windows.Forms.BarcodeControl;
                //    c1.CopyRight = c.Text;
                //    c1.Invalidate();
                //}
                //panel1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("预判错误:" + ex.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// 打印文档 林修改于2016-01-28
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            if (frmLabel != null)
            {
                e.PageSettings.Margins.Left = 0;
                e.PageSettings.Margins.Top  = 0;
                e.HasMorePages           = false;
                e.PageSettings.Landscape = false;
                StringFormat sf;
                sf           = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                e.Graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                for (int j = 0; j < frmLabel.panel1.Controls.Count; j++)
                {
                    //打印panel里面的MyBarCodeControl控件
                    if (frmLabel.panel1.Controls[j] is BarcodeLib.MyBarCodeControl)
                    {
                        BarcodeLib.MyBarCodeControl mybar = (BarcodeLib.MyBarCodeControl)frmLabel.panel1.Controls[j];


                        foreach (Control cBar in mybar.Controls)
                        {
                            //打印MyBarCodeControl里面的控件
                            string tn = cBar.GetType().Name;

                            if (tn == "Panel")
                            {
                                System.Windows.Forms.Panel panel = cBar as System.Windows.Forms.Panel;
                                int countt = 0;
                                for (int k = 0; k < panel.Controls.Count; k++)
                                {
                                    string pType = panel.Controls[k].GetType().Name;
                                    if (pType == "Label")
                                    {
                                        int add = (int)numericUpDown_bhg.Value;//编号
                                        if (countt % 2 == 0)
                                        {
                                            add = (int)numericUpDown_xmg.Value;//姓名
                                        }
                                        countt++;
                                        Label  label = panel.Controls[k] as Label;
                                        string text  = label.Text;
                                        float  new_x = (mybar.Location.X + label.Location.X + (int)numericUpDown1.Value) * (float)numericUpDown4.Value + (int)numericUpDown_hmz.Value;
                                        float  new_y = (mybar.Location.Y + label.Location.Y + (int)numericUpDown2.Value) * (float)numericUpDown4.Value + add;
                                        //float new_x = (mybar.Location.X + label.Location.X + (int)numericUpDown1.Value)  - 20;
                                        //float new_y = (mybar.Location.Y + label.Location.Y + (int)numericUpDown2.Value) + 20;
                                        Rectangle rect = new Rectangle(new Point((int)new_x, (int)new_y), label.Size);
                                        e.Graphics.PageScale = 1;
                                        //e.Graphics.PageScale = 0.7F;
                                        //e.Graphics.PageScale = (float)numericUpDown4.Value;
                                        e.Graphics.DrawString(label.Text, new Font(label.Font.Name, label.Font.Size, label.Font.Style), Brushes.Black, rect, sf);//-36
                                    }
                                    else if (pType == "PictureBox")
                                    {
                                        PictureBox pb    = panel.Controls[k] as PictureBox;
                                        Rectangle  rect1 = new Rectangle(new Point(mybar.Location.X + pb.Location.X + (int)numericUpDown1.Value, mybar.Location.Y + pb.Location.Y + (int)numericUpDown2.Value + (int)numericUpDown_tm.Value), pb.Size);
                                        e.Graphics.PageScale = (float)numericUpDown4.Value;
                                        e.Graphics.DrawImage(pb.Image, rect1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }