彩票走势图

Stimulsoft Reports.Net开发者常见Q&A——报表预览

原创|使用教程|编辑:郑恭琳|2015-12-18 11:21:17.000|阅读 2143 次

概述:本片文章主要介绍Stimulsoft Reports.Net开发者在预览报表时遇到的常见问题及解决方案。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

< Stimulsoft Reports.Net v2015.3最新版本下载>

1.自己怎么处理处理已渲染报表的保存和加载?

使用StiViewerControl类的静态事件SavingDocument和LoadingDocument。SavingDocument用来保存已渲染的报表,LoadingDocument用来加载已渲染的报表。
保存已渲染的报表处理方法如下:

C#

private static void OnSavingDocument(object sender, EventArgs e)
{
StiReport report = sender as StiReport;
report.SaveDocument("MyFile.mdc");
}
StiViewerControl.SavingDocument += new EventHandler(OnSavingDocument);

VB

Private Shared Sub OnSavingDocument(ByVal sender As Object, ByVal e As EventArgs)
Dim Report As StiReport = TryCast(sender, StiReport)
Report.SaveDocument("MyFile.mdc")
End Sub
AddHandler StiViewerControl.SavingDocument, New EventHandler(AddressOf
Form1.OnSavingDocument)

加载已渲染报表的处理方法如下:

C#

private static void OnLoadingDocument(object sender, EventArgs e)
{
StiReport report = sender as StiReport;
report.LoadDocument("MyFile.mdc");
}
StiViewerControl.LoadingDocument += new EventHandler(OnLoadingDocument);

VB

Private Shared Sub OnLoadingDocument(ByVal sender As Object, ByVal e As EventArgs)
Dim Report As StiReport = TryCast(sender, StiReport)
Report.LoadDocument("MyFile.mdc")
End Sub
AddHandler StiViewerControl.LoadingDocument, New EventHandler(AddressOf
Form1.OnLoadingDocument)

2.怎么实现在预览窗口打印报表?

使用StiPreviewControl类的静态事件PrintingDocument。方法如下:

C#

private static void OnPrintingDocument(object sender, EventArgs e)
{
StiReport report = sender as StiReport;
report.Print();
}}
StiPreviewControl.PrintingDocument += new EventHandler(OnPrintingDocument);

VB

Private Shared Sub OnPrintingDocument(ByVal sender As Object, ByVal e As EventArgs)
Dim Report As StiReport = TryCast(sender, StiReport)
Report.Print()
End Sub
AddHandler StiPreviewControl.PrintingDocument, New EventHandler(AddressOf
Form1.OnPrintingDocument)

3.怎么去掉工具栏里的按钮?

要想去掉预览窗口中的按钮,你需要修改StiPreviewConfig中的属性。

C#

//Do this operation once when running the program
StiConfig.Load();
//Get service
StiPreviewConfigService config = StiConfig.Services.GetService(typeof(StiPreviewConfigService)) as
StiPreviewConfigService;
//Turn off all buttons of changes of the rendered report
config.PageNewEnabled = false;
config.PageDeleteEnabled = false;
config.PageDesignEnabled = false;
config.PageSizeEnabled = false;
//Save configuration if necessary
StiConfig.Save();

VB

'Do this operation once when running the program
StiConfig.Load()
'Get service
Dim Config As StiPreviewConfigService =
TryCast(StiConfig.Services.GetService(GetType(StiPreviewConfigService)), StiPreviewConfigService)
Disable all buttons of changes of a rendered report
Config.PageNewEnabled = False
Config.PageDeleteEnabled = False
Config.PageDesignEnabled = False
Config.PageSizeEnabled = False
'Save configuration if necessary
StiConfig.Save()

使用Configurator.exe也可以得到相同的结果。此外你还可以使用StiPreviewControl,它包含许多用来控制预览窗口中控件可见性的属性。你还可以在报表设计器里修改PreviewSettings属性实现。    

4.怎么关闭工具栏?

使用StiPreviewControl可以关闭工具栏,将ShowToolbar的属性设置为false即可。

5.怎么指定报表生成器将结果输出到StiPreviewControl中?

有两种方法。第一种:

C#

StiReport report = new StiReport();
report.Load("MyReport.mrt");
report.Render();
myCustomPreview.Report = report;

VB

Dim Report As New StiReport
Report.Load("MyReport.mrt")
Report.Render()
MyCustomPreview.Report = Report

第二种:

C#

StiReport report = new StiReport();
report.PreviewControl = myCustomPreview;
report.Load("MyReport.mrt");
report.Show();

VB

Dim Report As New StiReport
Report.PreviewControl = MyCustomPreview
Report.Load("MyReport.mrt")
Report.Show()

6.怎么指定报表生成器使用我的预览窗口?

你的报表预览窗口需要有接收报表输入对象的构造函数。然后使用报表类的PreviewForm属性,该属性有Type类型。换句话说你的报表预览窗口将被第一个创建并显示出来。

C#

//Create a new window
public class Form1 : Form
{
public Form1(StiReport report)
{
}
}
//Fill the PreviewForm property
report.PreviewForm = typeof(Form1);

VB

'Create a new window
Public Class Form1
Inherits Form
Public Sub New(ByVal report As StiReport)
InitializeComponent()
End Sub
End Class
'Fill the PreviewForm property
Report1.PreviewForm = CType(GetType(Form1), Type)

7.怎么在StiPreviewControl中设置报表页面的缩放?

使用SetZoom方法。示例:

C#

//Set zoom 100%
myPreviewControl.SetZoom(1);

VB

'Set zoom 100%
MyPreviewControl.SetZoom(1)  

8.怎么在StiPreviewControl中设置报表页面的预定义缩放?

使用缩放设置的预定义方法:

C#

//Display the page
myPreviewControl.SetZoomOnePage();
//Display two pages
myPreviewControl.SetZoomTwoPages();
//Display multiple pages
myPreviewControl.SetZoomMultiplePages();
//Display a page. The page is to be aligned by the width in the StiPreviewControl
myPreviewControl.SetZoomPageWidth();

VB

'Display a page
MyPreviewControl.SetZoomOnePage()
'Display two pages
MyPreviewControl.SetZoomTwoPages()
'Display multiple pages
MyPreviewControl.SetZoomMultiplePages()
'Display a page. The page is to be aligned by the width in the StiPreviewControl
MyPreviewControl.SetZoomPageWidth()

9.怎么从报表的代码中将报表页面加载到已渲染的报表中?

C#

//Create a page
StiPage page = new StiPage();
//Load the page from a file
page.Load("MyPage.pg");
//Add a page to the collection of rendered pages
RenderedPages.Add(page);
//Refresh the window of preview
InvokeRefreshPreview();

VB

'Create a page
Dim Page As New StiPage
'Load the page from a file
Page.Load("MyPage.pg")
'Add a page to the collection of rendered pages
Report.RenderedPages.Add(Page)
'Refresh the window of preview
Report.InvokeRefreshPreview()

10.怎么在报表代码中刷新报表预览?

使用报表生成器的InvokeRefreshPreview方法:

C#

this.InvokeRefreshPreview();

VB

Me.InvokeRefreshPreview()

11.怎么访问已渲染报表的页面?

使用报表的RenderedPages属性:

C#

foreach (StiPage page in report.RenderedPages)
{
}

VB

Dim page As StiPage
For Each page In MyBase.RenderedPages
Next

12.怎么在预览中显示所有组件而不打印它们?

使用Printable属性:

  • True-组件会显示在设计器中并且会被打印
  • False-组件会显示在设计器中但是不会被打印

13.怎么在报表的代码中给已渲染的报表添加或修改图像?

创建或新增一个组件:

C#

StiImage image = new StiImage();
image.Left = 0;
image.Top = 0;
image.Width = 10;
image.Height = 10;
//An image name should be unique in your report
image.Name = "MyUniqueName";
//Assign an image
image.Image = myImage;
//Add a component with an image with a report
report.Pages[0].Components.Add(image);

VB

Dim Image As StiImage = New StiImage()
Image.Left = 0
Image.Top = 0
Image.Width = 10
Image.Height = 10
'An image name should be unique in your report
Image.Name = "MyUniqueName"
'Assign an image
Image.Image = myImage
'Add a component with an image with a report
Report.Pages(0).Components.Add(Image)

如果报表已经从程序集中编译或加载,替换图像需要使用ImageToDraw属性。    
修改报表中的图像有两种方法:
第一种-报表还没被编译
在报表中找到包含图像的组件:

C#

StiImage image = report.GetComponents()["image1"] as StiImage;

VB

Dim Image As StiImage = CType(Report.GetComponents()("image1"), StiImage)

修改图像:

C#

image.Image = myImage;

VB

Image.Image = MyImage

这种方法,你的图像你的图像被转换成代码,然后报表回编译且运行它。
第二种-报表从程序集中加载且编译过
编译报表

C#

report.Compile();

VB

Report.Compile()

找到组件

C#

StiImage image = report.GetComponents()["image1"] as StiImage;

VB

Dim Image As StiImage = CType(Report.GetComponents()("image1"), StiImage)

指定图像:

C#

image.ImageToDraw = myImage;

VB

Image.ImageToDraw = MyImage

14.怎么在预览窗口中只显示被取消的按钮而不显示报表?

使用报表的IsStopped属性:

C#

if (!report.IsStopped)

15.怎么附加渲染页面的指示器?

使用报表的Rendering事件。示例如下:

C#

//Create a new report
StiReport report = new StiReport();
report.Load("report.mrt");
//Compile this report by all means
report.Compile();
//Add to the Rendering event of a compiled report
report.CompiledReport.Rendering += new EventHandler(this.OnRendering);
//Start report rendering. Attention! The Render method is called from False arguments.
//This argument indicates that there is no need to show progress of report rendering
report.Render(false);
//Show the rendered report
report.Show();
//The event which we are attaching
private void OnRendering(object sender, EventArgs e)
{
StiReport report = sender as StiReport;
string info = (report.PageNumber -1).ToString();
}

VB

'Create a new report
Dim Report As New StiReport
Report.Load("report.mrt")
'Compile this report by all means
Report.Compile()
'Add to the Rendering event of a compiled report
AddHandler Report.CompiledReport.Rendering, New EventHandler(AddressOf Me.OnRendering)
'Start report rendering. Attention! The Render method is called from False arguments.
'This argument indicates that there is no need to show progress of report rendering
Report.Render(False)
'Show the rendered report
Report.Show()
'The event which we are attaching
Private Sub OnRendering(ByVal sender As Object, ByVal e As EventArgs)
Dim Report As StiReport = CType(sender, StiReport)
Dim Info As String = (Report.PageNumber -1).ToString()
End Sub

注意!你必须附加到report.CompiledReport,只有这样才能运行Compile方法。

购买最新正版授权!""

慧都年终盛典火爆开启,一年仅一次的最强促销,破冰钜惠不容错过!!优惠详情点击查看>>


标签:报表解决方案报表.NET报表控件

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP