找回密码
 立即注册

QQ登录

只需一步,快速开始

ZenosZeng 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-10-31 18:40  /   查看:4892  /  回复:0
ActiveReports 7本身没有对WPF系统提供支持,不过我们可以通过WPF提供的WindowsFromHost控件来实现这一功能,通过WindowsFromHost可以在WPF系统中使用WinForms平台的控件。所以,我们只需要将ActiveReports 7的Viewer控件通过WindowsFormHost进行宿主就可以在WPF中浏览ActiveReports 7开发出来的报表。

详细操作步骤如下:
1、在Visual Studio中创建一个WPF应用程序
2、在工程中添加一个ActiveReports 7 Section Report (code-based)类型的报表文件
3、在工程中添加一个ActiveReports 7 Page Report类型的报表文件
4、在XAML设计界面添加一个WindowsFormsHost控件
5、在XAML的后台代码中添加以下代码:
  1.     private void btnSectionRpt_Click(object sender, RoutedEventArgs e)
  2.     {
  3.         Invoice rpt = new Invoice();
  4.          
  5.         rpt.Run();
  6.         viewer1.Document = rpt.Document;
  7.         windowsFormsHost2.Child = viewer1;

  8.     }

  9.     private void btnPageReport_Click(object sender, RoutedEventArgs e)
  10.     {
  11.         string file_name = GetPath("Invoice1.rdlx");
  12.         GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
  13.         GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
  14.         viewer1.LoadDocument(pageDocument);
  15.         windowsFormsHost2.Child = viewer1;
  16.     }
复制代码


运行截图:


源码下载:VS2010 + ActiveReports 7

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部