翻譯|使用教程|編輯:王香|2018-08-21 10:43:12.000|閱讀 518 次
概述:本文主要講解如何在運(yùn)行時(shí)創(chuàng)建一個(gè)新報(bào)表
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
【下載Stimulsoft Reports.Ultimate最新版本】
此示例顯示如何在運(yùn)行時(shí)創(chuàng)建簡單報(bào)表,讓我們創(chuàng)建包含標(biāo)題,數(shù)據(jù),總計(jì)的報(bào)表,并在查看器中顯示它。首先,創(chuàng)建一個(gè)新報(bào)表并將數(shù)據(jù)源添加到dictionary中:
private void button1_Click(object sender, System.EventArgs e)
{
StiReport report = new StiReport();
//Add data to datastore
report.RegData(dataSet1);
//Fill dictionary
report.Dictionary.Synchronize();
StiPage page = report.Pages[0];
...
添加Header Band與Text Boxes,并為其指定data titles:
...
//Create HeaderBand
StiHeaderBand headerBand = new StiHeaderBand();
headerBand.Height = 0.5;
headerBand.Name = "HeaderBand";
page.Components.Add(headerBand);
//Create text on header
StiText headerText = new StiText(new RectangleD(0, 0, 5, 0.5));
headerText.Text = "CompanyName";
headerText.HorAlignment = StiTextHorAlignment.Center;
headerText.Name = "HeaderText";
headerText.Brush = new StiSolidBrush(Color.LightGreen);
headerBand.Components.Add(headerText);
...
接下來,添加帶有Text Boxes的Data Band,其中包含對數(shù)據(jù)字段的引用:
...
//Create Databand
StiDataBand dataBand = new StiDataBand();
dataBand.DataSourceName = "Customers";
dataBand.Height = 0.5;
dataBand.Name = "DataBand";
page.Components.Add(dataBand);
//Create text
StiText dataText = new StiText(new RectangleD(0, 0, 5, 0.5));
dataText.Text = "{Line}.{Customers.CompanyName}";
dataText.Name = "DataText";
dataBand.Components.Add(dataText);
...
下一步,添加帶有Text Boxes的Footer Band,其中包含數(shù)據(jù)總計(jì)的功能:
...
//Create FooterBand
StiFooterBand footerBand = new StiFooterBand();
footerBand.Height = 0.5;
footerBand.Name = "FooterBand";
page.Components.Add(footerBand);
//Create text on footer
StiText footerText = new StiText(new RectangleD(0, 0, 5, 0.5));
footerText.Text = "Count - {Count()}";
footerText.HorAlignment = StiTextHorAlignment.Right;
footerText.Name = "FooterText";
footerText.Brush = new StiSolidBrush(Color.LightGreen);
footerBand.Components.Add(footerText);
...
最后,在查看器中顯示報(bào)表:
...
report.Show();
}
示例代碼的結(jié)果如下圖所示:

本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn