将控件添加到活动报表的设计器中
本文关键字:报表 控件 添加 活动 | 更新日期: 2023-09-27 18:29:56
我知道在活动报表中添加控件有不同的方法。我在不同的网页上找到了它们,比如:
this.Sections["groupHeader1"].Controls.Add(txt);
但这不关我的事,我必须加载设计器,即带有一些控件的GrapeCity.ActiveReport.Design.Designer
。我想从我的代码后面添加这些控件。请帮帮我。
如果您正在使用最终用户设计器进行查找,并希望将控件添加到基于节的报表节,则需要使用SectionReport类强制转换最终用户设计器报表,并相应地访问其节。例如,检查以下代码,该代码在点击按钮时将文本框添加到报告的"详细信息"部分:
private void button1_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.SectionReportModel.TextBox txtBox = new GrapeCity.ActiveReports.SectionReportModel.TextBox();
txtBox.Text = "Hello World!";
txtBox.Location = new Point(1, 1);
txtBox.Size = new SizeF(2, 0.5f);
((GrapeCity.ActiveReports.SectionReport)reportdesigner.Report).Sections["Detail"].Controls.Add(txtBox);
}
此处reportDesigner是设计器控件的名称。希望这能有所帮助。
我已经通过有一个新的SectionReport
并在其中采用Designer.Report
来完成了。现在在SectionReport
中添加控件意味着在Designer.Report
中添加控件。这就是我对以下解决方案的看法,因为它对我有效
Dim sr As New GrapeCity.ActiveReports.SectionReport()
sr = Me.reportdesigner.Report
''Adding Detail section
sr.Sections.Insert(1, New GrapeCity.ActiveReports.SectionReportModel.Detail())
sr.Sections(1).BackColor = Color.PeachPuff
sr.Sections(1).Height = 1.5F
Dim lbl2 As New GrapeCity.ActiveReports.SectionReportModel.Label()
lbl2.Location = New PointF(0, 0.05F)
lbl2.Text = "Category ID"
lbl2.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center
lbl2.Font = New System.Drawing.Font("Arial", 10, FontStyle.Bold)
sr.Sections(1).Controls.Add(lbl2)
如果这个答案中有任何问题,请报告我。
下面是可以放入Form.的加载事件中的代码
GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();
sectionReport.Sections.Add(GrapeCity.ActiveReports.Document.Section.SectionType.Detail, "Body");
GrapeCity.ActiveReports.SectionReportModel.TextBox MyTextBox = new GrapeCity.ActiveReports.SectionReportModel.TextBox();
MyTextBox.Text = "My Runtime Text";
MyTextBox.ShrinkToFit = true;
MyTextBox.DataField = "ID";
sectionReport.Sections[0].Controls.Add(MyTextBox);