Exemplo n.º 1
0
        private void button_Preview_Click(object sender, EventArgs e)
        {
            //对打印信息进行设置
            PrintClass dgp = new PrintClass(this.dataGridView1, this.textBox_Title.Text, 16, comboBox_PageSize.SelectedIndex, checkBox_Aspect.Checked);

            MSetUp(dgp);                                             //记录窗体中打印信息的相关设置
            string[] header = new string[dataGridView1.ColumnCount]; //创建一个与数据列相等的字符串数组
            for (int p = 0; p < dataGridView1.ColumnCount; p++)      //记录所有列标题的名列
            {
                header[p] = dataGridView1.Columns[p].HeaderCell.Value.ToString();
            }
            dgp.print();//显示打印预览窗体
        }
Exemplo n.º 2
0
        public bool boundary   = false; //是否打印分割线


        #region  设置打印数据的相关信息
        /// <summary>
        /// 设置打印数据的相关信息
        /// </summary>
        /// <param dgp="PrintClass">公共类PrintClass</param>
        public void MSetUp(PrintClass dgp)
        {
            string n = "false";

            string[] margin = new string[4];
            if (checkBox_margin.Checked == true)
            {
                n = "true";
            }
            else
            {
                n = "alse";
            }
            margin[0] = n;
            margin[1] = textBox_topmargin.Text;
            margin[2] = textBox_leftmargin.Text;
            margin[3] = textBox_buttommargin.Text;
            dgp.PrintSetUp(margin);
            dgp.headerheight = this.header;                                                                  //列标题的默认高度
            if (checkBox_Header.Checked == true)                                                             //列标题
            {
                dgp.brushHeaderFont = new SolidBrush(dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor); //前景色
                dgp.headerfont      = dataGridView1.ColumnHeadersDefaultCellStyle.Font;                      //字体样式
                dgp.brushHeaderBack = new SolidBrush(dataGridView1.ColumnHeadersDefaultCellStyle.BackColor); //背景色
                dgp.headerheight    = dataGridView1.ColumnHeadersHeight;                                     //列标题的高度
            }
            if (checkBox_Cell.Checked == true)                                                               //单元格
            {
                dgp.Cellfont      = dataGridView1.RowsDefaultCellStyle.Font;                                 //字体样式
                dgp.brushCellBack = new SolidBrush(dataGridView1.RowsDefaultCellStyle.BackColor);            //背景色
                dgp.brushCellFont = new SolidBrush(dataGridView1.RowsDefaultCellStyle.ForeColor);            //前景色
                dgp.rowgap        = row;
            }
            if (checkBox_Table.Checked == true)                            //表格
            {
                dgp.AlignmentSgin = this.comboBox_Alignment.SelectedIndex; //对齐方式
            }
            dgp.iseverypageprinttitle = checkBox_Title.Checked;            //是否每一页都打印标题
            dgp.needprintpageindex    = checkBox_Page.Checked;             //是否每一页都打印页脚
            dgp.PageAspect            = Aspect;                            //设置横向打印
            //设置表格的边线
            dgp.LineUP     = PLintUP;                                      //是否打印上边线
            dgp.LineLeft   = PLintLeft;                                    //是否打印左边线
            dgp.LineUnit   = PLintUnit;                                    //是否打印单元格边线
            dgp.LineColor  = linecolor;                                    //设置线的颜色
            dgp.Boundary   = checkBox_Boundary.Checked;                    //是否打印分割线
            dgp.HAlignment = comboBox_HAlignment.SelectedIndex;            //列标题的对齐方式
            dgp.UAlignment = comboBox_UAlignment.SelectedIndex;            //单元格的对齐方式
        }