原創(chuàng)|使用教程|編輯:郝浩|2013-08-07 09:37:57.000|閱讀 385 次
概述:報表控件ActiveReports的最新7版本提供了更多更廣泛的API,讓Visual Basic和C#開發(fā)者可以完整掌控報表流程引擎,以適應(yīng)各種復(fù)雜報表開發(fā)的需求。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
報表控件ActiveReports的最新7版本提供了更多更廣泛的API,讓Visual Basic和C#開發(fā)者可以完整掌控報表流程引擎,以適應(yīng)各種復(fù)雜報表開發(fā)的需求。
它主要提供的事件和屬性類型有:
完善的API意味著開發(fā)人員實現(xiàn)在運行時創(chuàng)建報表,一般的報表工具都將報表設(shè)計和報表分開運行扯淡,而ActiveReports卻可以通過API實現(xiàn)運行時的報表創(chuàng)建,讓一些報表的一些動態(tài)功能能夠?qū)崿F(xiàn)。接下來就以如何創(chuàng)建動態(tài)區(qū)段報表為例,說一下靈活運用API的方法。首先看一下最終創(chuàng)建報表的效果:
簡單的說一下創(chuàng)建步驟:
下段代碼就能完成所有步驟:
private void Form1_Load(object sender, EventArgs e) { rpt = new SectionReport(); //Adding Page Header/Footer sections rpt.Sections.InsertPageHF(); rpt.Sections[0].BackColor = Color.LightGray; //Adding Detail section rpt.Sections.Insert(1, new Detail()); rpt.Sections[1].BackColor = Color.PeachPuff; rpt.Sections[1].Height = 1.5f; //Adding label to display first column's name GrapeCity.ActiveReports.SectionReportModel.Label lblCategoryID = new GrapeCity.ActiveReports.SectionReportModel.Label(); lblCategoryID.Location = new PointF(0, 0.05F); lblCategoryID.Text = "Category ID"; lblCategoryID.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center; lblCategoryID.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold); rpt.Sections[0].Controls.Add(lblCategoryID); //Adding label to display second column's name GrapeCity.ActiveReports.SectionReportModel.Label lblCategoryName = new GrapeCity.ActiveReports.SectionReportModel.Label(); lblCategoryName.Location = new PointF(1.459f, 0.05f); lblCategoryName.Size = new SizeF(1.094f,0.2f); lblCategoryName.Text = "Category Name"; lblCategoryName.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold); rpt.Sections[0].Controls.Add(lblCategoryName); //Adding label to display third column's name GrapeCity.ActiveReports.SectionReportModel.Label lblDescription = new GrapeCity.ActiveReports.SectionReportModel.Label(); lblDescription.Location = new PointF(3.114f, 0.05f); lblDescription.Text = "Description"; lblDescription.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold); rpt.Sections[0].Controls.Add(lblDescription); //Adding label to display fourth column's name GrapeCity.ActiveReports.SectionReportModel.Label lblPicture = new GrapeCity.ActiveReports.SectionReportModel.Label(); lblPicture.Location = new PointF(5.219f, 0.05f); lblPicture.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center; lblPicture.Text = "Picture"; lblPicture.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold); rpt.Sections[0].Controls.Add(lblPicture); //Adding Textbox to display first column's records GrapeCity.ActiveReports.SectionReportModel.TextBox txtCategoryID = new GrapeCity.ActiveReports.SectionReportModel.TextBox(); txtCategoryID.Location = new PointF(0,0); txtCategoryID.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center; rpt.Sections[1].Controls.Add(txtCategoryID); //Adding Textbox to display second column's records GrapeCity.ActiveReports.SectionReportModel.TextBox txtCategoryName = new GrapeCity.ActiveReports.SectionReportModel.TextBox(); txtCategoryName.Location = new PointF(1.459f,0); rpt.Sections[1].Controls.Add(txtCategoryName); //Adding Textbox to display third column's records GrapeCity.ActiveReports.SectionReportModel.TextBox txtDescription = new GrapeCity.ActiveReports.SectionReportModel.TextBox(); txtDescription.Location = new PointF(3.114f,0); rpt.Sections[1].Controls.Add(txtDescription); //Adding Picture control to display image GrapeCity.ActiveReports.SectionReportModel.Picture picture = new Picture(); picture.Location = new PointF(5.219f,0); rpt.Sections[1].Controls.Add(picture); // Setting report's data source conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\stduser\Documents\ComponentOne Samples\ActiveReports Developer 7\Data\NWIND.mdb;Persist Security Info=False"); System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("SELECT * FROM Categories", conn); conn.Open(); reader = cmd.ExecuteReader(); rpt.DataSource = reader; // Assigning DataField properties of controls in the detail section txtCategoryID.DataField = "CategoryID"; txtCategoryName.DataField = "CategoryName"; txtDescription.DataField = "Description"; picture.DataField = "Picture"; reader.Close(); conn.Close(); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)