ReportViewer 2010 C#上的打印预览问题 [英] Print Preview Issue on ReportViewer 2010 C#

查看:352
本文介绍了ReportViewer 2010 C#上的打印预览问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我有一个报表查看器,当用户点击按钮时以编程方式显示rdlc报告

按钮事件我做以下内容:



 System.Drawing.Printing.PageSettings pg =  new  System.Drawing.Printing.PageSettings(); 
pg.Landscape = true ;
pg.Margins.Top = 2 ;
pg.Margins.Bottom = 2 ;
pg.Margins.Left = 40 ;
pg.Margins.Right = 2 ;
system.Drawing.Printing.PaperSize size = new PaperSize();
size.RawKind =( int )PaperKind.A4Extra;
pg.PaperSize = size;
reportViewer1.SetPageSettings(pg);

DataTable dt = ReceiptsManager.GetAvowelsReportDT(< Parameters>);

if (dt!= null && dt.Rows。计数> 0
{
reportViewer1.LocalReport.ReportPath =<

ReportDataSource RDS = new ReportDataSource();
RDS.Name =< RDLC报告数据集名称> ;;
RDS.Value = dt;
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(RDS);

this .reportViewer1.RefreshReport();
}





报告显示效果不错但点击 Printpreview 按钮观众显示一个没有任何内容的黑色小盒子,当我按下右键并选择一个页面设置时,我看到了我的预定义设置,当我按下OK时显示的报告



所以我想解决这个问题,当用户点击 Printpreview 时,显示预定义设置的报告



提前谢谢

解决方案

hi
i长时间遇到同样的问题,毕竟我想出来了。



纸张尺寸已经一些值,如高度和宽度。

当您创建PaperSize的新对象时,这些值设置为零,当您将纸张设置为A4时,这些值再次为零。因此,您的纸张尺寸未定义,只要您打开pagesetup并单击OK,PaperSize就会设置为其真实值。



因此您必须手动设置它们。我使用页面默认PaperSize并修改它而不是制作一个新对象,我的程序工作正常。



所以只需更换你的代码:

 system.Drawing.Printing.PaperSize size = new PaperSize(); 



并将其放入:

 system.Drawing.Printing.PaperSize size = pg.PaperSize; 





在我的情况下解决了这个问题


Hi everyone

I have a report viewer that programmatically display a rdlc report when user click a button
in button event i do the following:

System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
pg.Landscape = true;
pg.Margins.Top = 2;
pg.Margins.Bottom = 2;
pg.Margins.Left = 40;
pg.Margins.Right = 2;
system.Drawing.Printing.PaperSize size = new PaperSize();
size.RawKind = (int)PaperKind.A4Extra;
pg.PaperSize = size;
reportViewer1.SetPageSettings(pg);

DataTable dt = ReceiptsManager.GetAvowelsReportDT(<Parameters>);

if (dt != null && dt.Rows.Count > 0)
{
  reportViewer1.LocalReport.ReportPath = <RDLC Report Path>

  ReportDataSource RDS = new ReportDataSource();
  RDS.Name = <RDLC Report Dataset Name>;
  RDS.Value = dt;
  reportViewer1.LocalReport.DataSources.Clear();
  reportViewer1.LocalReport.DataSources.Add(RDS);

  this.reportViewer1.RefreshReport();
}



the report displayed well but when i click on Printpreview button the viewer displayed a small black box without any contents and when i press right click and choose a pagesetup i see my predefined settings and when i press OK the report displayed

So i want to solve this problem and when user click Printpreview the report displayed with predefined settings

Thanks in advance

解决方案

hi i had the same problem for long long time and after all i figured it out.

paper size has some values like height and width.
when you make a new object of PaperSize, these values are set to zero and when you set your paper to be A4, these values are zero again. so your paper size is not defined and as soon as you open pagesetup and click OK, the PaperSize is set to its true values.

so you have to set them manually. i used the pages default PaperSize and modified it instead of making a new object and my program worked correctly.

so just replace your code :

system.Drawing.Printing.PaperSize size = new PaperSize();


and put this:

system.Drawing.Printing.PaperSize size = pg.PaperSize;



in my case this solve the problem


这篇关于ReportViewer 2010 C#上的打印预览问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆