以下的示例演示了如何在运行时添加注解,并保存报表数据和注解到一个 RDF 文件中。
1. 双击视图所在宿主窗体的标题栏。这会创建一个对应于 form Load 事件的处理程序。
2. 添加代码到事件处理程序,然后运行报表,添加注解,显示报表在视图中,并保存报表到一个 RDF 文件。
使用 Visual Basic 编写以下代码
Visual Basic.NET 代码,粘贴于类上方。
Imports GrapeCity.ActiveReports.Document.Section.Annotations |
Visual Basic.NET 代码。粘贴于事件 Form Load 内。
Dim rpt As New SectionReport1 'Run the report first. rpt.Run()
'Assign the viewer. Me.Viewer1.Document = rpt.Document
'Create an annotation and assign property values. Dim circle As New AnnotationCircle circle.Color = System.Drawing.Color.GreenYellow circle.Border.Color = System.Drawing.Color.Chartreuse
'Add the annotation. circle.Attach(1,1) 'screen location Me.Viewer1.Document.Pages(0).Annotations.Add(circle)
'Set the size properties. The annotation must be added to the page first. circle.Height = 0.25 circle.Width = 0.50
'Save annotations with the report in an RDF file. rpt.Document.Save("C:\AnnotatedReport.rdf") |
使用 C# 编写以下代码
C# 代码。 粘贴于类上方。
using GrapeCity.ActiveReports.Document.Section.Annotations; |
C# 代码。 粘贴于事件 Form Load 内。
SectionReport1 rpt = new SectionReport1(); //Run the report first. rpt.Run();
//Assign the viewer this.viewer1.Document = rpt.Document;
//Create an annotation and assign property values. AnnotationCircle circle = new AnnotationCircle(); circle.Color = System.Drawing.Color.GreenYellow; circle.Border.Color = System.Drawing.Color.Chartreuse;
//Add the annotation. circle.Attach(1,1); //screen location this.viewer1.Document.Pages[0].Annotations.Add(circle);
//Set the size properties. The annotation must be added to the page first. circle.Height = 0.25f; circle.Width = 0.50f;
//Save annotations with the report in an RDF file. rpt.Document.Save("C:\\AnnotatedReport.rdf"); |