我在winforms的rdlc中创建了一个报告。这工作正常。但是,在我将页面设置添加到报表查看器后,打印布局视图无法正确显示。只显示黑点。当我评论页面设置时,它正常工作。
我的报告绑定编码低于
this.reportViewer1.Width = this.Width - 15;
this.reportViewer1.Height = this.Height - 15;
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";
ReportDataSource rds = new ReportDataSource("DataSet1", CustomerList);
rds.Value = _deliveryNote.CustomerList;
this.reportViewer1.LocalReport.DataSources.Add(rds);
System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
pg.Margins.Top = 100;
pg.Margins.Bottom = 100;
pg.Margins.Left = 100;
pg.Margins.Right = 100;
pg.Landscape = false;
System.Drawing.Printing.PaperSize size = new PaperSize();
size.RawKind = (int)PaperKind.A4;
pg.PaperSize = size;
this.reportViewer1.SetPageSettings(pg);
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
答案 0 :(得分:0)
这是因为您没有指定纸张的高度和宽度。如下更改代码将解决您的问题:
System.Drawing.Printing.PageSettings pg = new PageSettings();
// Set margins
pg.Margins = new System.Drawing.Printing.Margins(100, 100, 100, 100);
// Set paper size
pg.PaperSize = new PaperSize("A4", 827, 1169); // 8.27 in x 11.69 in
pg.RawKind = (int)PaperKind.A4; // Before .NET Framework 4.5
// Update report and refresh
this.reportViewer1.SetPageSettings(pg);
this.reportViewer1.RefreshReport();
// Switch to print Layout (optional)
this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
对于.NET Framework 4.5及更高版本,需要按如下方式设置RawKind。谢谢你指出@Tyler Durden。
pg.PaperSize.RawKind = (int)PaperKind.A4;
希望这有助于将来。