0

我知道有不同的方法可以在 Active Report 中添加控件。我在不同的网页上找到了它们,例如:

this.Sections["groupHeader1"].Controls.Add(txt);

但这不关我的事,我必须加载设计器,即GrapeCity.ActiveReport.Design.Designer带有一些控件。我想从我的代码后面添加这些控件。请帮我。

4

3 回答 3

1

如果您正在使用最终用户设计器并希望将控件添加到基于部分的报告部分,那么您将需要使用 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 是设计器控件的名称。希望这可以帮助。

于 2014-11-12T03:38:07.163 回答
0

我通过拥有一个新的SectionReport并采用它来做到这Designer.Report一点。现在添加控件 inSectionReport意味着,添加控件 in 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)

如果此答案中有任何问题,请报告我。

于 2014-11-12T04:39:11.490 回答
0

以下是您可以放入 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);
于 2017-03-08T13:15:03.190 回答