报告中的每个部分都有一个控件集合,该集合显示该部分中的控件集合。Sections 集合上的主题有一个很好的示例,说明如何以编程方式将控件添加到集合中。下面是一些注释的摘录,以帮助解释:
' Insert Group Header and Footer Sections:'
Me.Sections.InsertGroupHF()
' Set some proprties to configure those sections:
CType(Me.Sections("GroupHeader1"), GroupHeader).DataField = "CategoryID"
Me.Sections("GroupHeader1").BackColor = System.Drawing.Color.SlateBlue
Me.Sections("GroupHeader1").CanGrow = True
Me.Sections("GroupHeader1").CanShrink = True
CType(Me.Sections("GroupHeader1"), GroupHeader).RepeatStyle = RepeatStyle.OnPageIncludeNoDetail
Me.Sections("GroupHeader1").Height = 0
' Create a TexBox control & Set some properties to configure that control
Dim txt As New TextBox()
txt.DataField = "CatagoryID"
txt.Location = New System.Drawing.PointF(0.0F, 0)
txt.Width = 2.0F
txt.Height = 0.3F
txt.Style = "font-weight: bold; font-size: 16pt"
' Add the TextBox to the GroupHeader section:
Me.Sections("GroupHeader1").Controls.Add(txt)
ActiveReports 6 文档有一个名为 Run Time Layouts 的演练,它构建了一个在代码中构建报表布局的整个应用程序。这是准确了解如何通过代码操作报表的好方法。