打印grid

void PrintButtonClick(object sender, EventArgs e)

        {

            PrintPreviewDialog dlg = new PrintPreviewDialog();

            

            //page setting 

            PageSetupDialog psp = new PageSetupDialog();

            psp.AllowMargins = true;

            SourceGrid.Exporter.GridPrintDocument pd = new SourceGrid.Exporter.GridPrintDocument(this.grid);



            //页边距开关 若关闭:打印时页边距设置无效、不起作用的原因及解决方法

            pd.OriginAtMargins = true;

            //是否 横向打印

            pd.DefaultPageSettings.Landscape = true;

            //左边距 左边距宽度(以百分之一英寸为单位)

            pd.DefaultPageSettings.Margins.Left = 210;

            psp.PageSettings = pd.DefaultPageSettings;

            //显示 英寸还是毫米

            psp.EnableMetric = true;



            if (psp.ShowDialog() == DialogResult.OK)

            {

                pd.DefaultPageSettings = psp.PageSettings;

            }



            

            pd.RangeToPrint = new SourceGrid.Range(0, 0, this.grid.Rows.Count - 1, this.grid.Columns.Count - 1);

            pd.PageHeaderText = "Print sample\t\tSourceGrid print document sample";

            pd.PageTitleText = "\tSample grid";

            pd.PageFooterText = "\tPage [PageNo] from [PageCount]";

            dlg.Document = pd;

            dlg.ShowDialog(this);

        }

 

你可能感兴趣的:(grid)