原創(chuàng)|使用教程|編輯:鄭恭琳|2015-12-18 11:21:17.000|閱讀 2210 次
概述:本片文章主要介紹Stimulsoft Reports.Net開發(fā)者在預(yù)覽報(bào)表時(shí)遇到的常見問(wèn)題及解決方案。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
< Stimulsoft Reports.Net v2015.3最新版本下載>
使用StiViewerControl類的靜態(tài)事件SavingDocument和LoadingDocument。SavingDocument用來(lái)保存已渲染的報(bào)表,LoadingDocument用來(lái)加載已渲染的報(bào)表。
保存已渲染的報(bào)表處理方法如下:
C#
private static void OnSavingDocument(object sender, EventArgs e) { StiReport report = sender as StiReport; report.SaveDocument("MyFile.mdc"); } StiViewerControl.SavingDocument += new EventHandler(OnSavingDocument);
VB
Private Shared Sub OnSavingDocument(ByVal sender As Object, ByVal e As EventArgs) Dim Report As StiReport = TryCast(sender, StiReport) Report.SaveDocument("MyFile.mdc") End Sub AddHandler StiViewerControl.SavingDocument, New EventHandler(AddressOf Form1.OnSavingDocument)
加載已渲染報(bào)表的處理方法如下:
C#
private static void OnLoadingDocument(object sender, EventArgs e) { StiReport report = sender as StiReport; report.LoadDocument("MyFile.mdc"); } StiViewerControl.LoadingDocument += new EventHandler(OnLoadingDocument);
VB
Private Shared Sub OnLoadingDocument(ByVal sender As Object, ByVal e As EventArgs) Dim Report As StiReport = TryCast(sender, StiReport) Report.LoadDocument("MyFile.mdc") End Sub AddHandler StiViewerControl.LoadingDocument, New EventHandler(AddressOf Form1.OnLoadingDocument)
使用StiPreviewControl類的靜態(tài)事件PrintingDocument。方法如下:
C#
private static void OnPrintingDocument(object sender, EventArgs e) { StiReport report = sender as StiReport; report.Print(); }} StiPreviewControl.PrintingDocument += new EventHandler(OnPrintingDocument);
VB
Private Shared Sub OnPrintingDocument(ByVal sender As Object, ByVal e As EventArgs) Dim Report As StiReport = TryCast(sender, StiReport) Report.Print() End Sub AddHandler StiPreviewControl.PrintingDocument, New EventHandler(AddressOf Form1.OnPrintingDocument)
要想去掉預(yù)覽窗口中的按鈕,你需要修改StiPreviewConfig中的屬性。
C#
//Do this operation once when running the program StiConfig.Load(); //Get service StiPreviewConfigService config = StiConfig.Services.GetService(typeof(StiPreviewConfigService)) as StiPreviewConfigService; //Turn off all buttons of changes of the rendered report config.PageNewEnabled = false; config.PageDeleteEnabled = false; config.PageDesignEnabled = false; config.PageSizeEnabled = false; //Save configuration if necessary StiConfig.Save();
VB
'Do this operation once when running the program StiConfig.Load() 'Get service Dim Config As StiPreviewConfigService = TryCast(StiConfig.Services.GetService(GetType(StiPreviewConfigService)), StiPreviewConfigService) Disable all buttons of changes of a rendered report Config.PageNewEnabled = False Config.PageDeleteEnabled = False Config.PageDesignEnabled = False Config.PageSizeEnabled = False 'Save configuration if necessary StiConfig.Save()
使用Configurator.exe也可以得到相同的結(jié)果。此外你還可以使用StiPreviewControl,它包含許多用來(lái)控制預(yù)覽窗口中控件可見性的屬性。你還可以在報(bào)表設(shè)計(jì)器里修改PreviewSettings屬性實(shí)現(xiàn)。
使用StiPreviewControl可以關(guān)閉工具欄,將ShowToolbar的屬性設(shè)置為false即可。
有兩種方法。第一種:
C#
StiReport report = new StiReport(); report.Load("MyReport.mrt"); report.Render(); myCustomPreview.Report = report;
VB
Dim Report As New StiReport Report.Load("MyReport.mrt") Report.Render() MyCustomPreview.Report = Report
第二種:
C#
StiReport report = new StiReport(); report.PreviewControl = myCustomPreview; report.Load("MyReport.mrt"); report.Show();
VB
Dim Report As New StiReport Report.PreviewControl = MyCustomPreview Report.Load("MyReport.mrt") Report.Show()
你的報(bào)表預(yù)覽窗口需要有接收?qǐng)?bào)表輸入對(duì)象的構(gòu)造函數(shù)。然后使用報(bào)表類的PreviewForm屬性,該屬性有Type類型。換句話說(shuō)你的報(bào)表預(yù)覽窗口將被第一個(gè)創(chuàng)建并顯示出來(lái)。
C#
//Create a new window public class Form1 : Form { public Form1(StiReport report) { } } //Fill the PreviewForm property report.PreviewForm = typeof(Form1);
VB
'Create a new window Public Class Form1 Inherits Form Public Sub New(ByVal report As StiReport) InitializeComponent() End Sub End Class 'Fill the PreviewForm property Report1.PreviewForm = CType(GetType(Form1), Type)
使用SetZoom方法。示例:
C#
//Set zoom 100% myPreviewControl.SetZoom(1);
VB
'Set zoom 100% MyPreviewControl.SetZoom(1)
使用縮放設(shè)置的預(yù)定義方法:
C#
//Display the page myPreviewControl.SetZoomOnePage(); //Display two pages myPreviewControl.SetZoomTwoPages(); //Display multiple pages myPreviewControl.SetZoomMultiplePages(); //Display a page. The page is to be aligned by the width in the StiPreviewControl myPreviewControl.SetZoomPageWidth();
VB
'Display a page MyPreviewControl.SetZoomOnePage() 'Display two pages MyPreviewControl.SetZoomTwoPages() 'Display multiple pages MyPreviewControl.SetZoomMultiplePages() 'Display a page. The page is to be aligned by the width in the StiPreviewControl MyPreviewControl.SetZoomPageWidth()
C#
//Create a page StiPage page = new StiPage(); //Load the page from a file page.Load("MyPage.pg"); //Add a page to the collection of rendered pages RenderedPages.Add(page); //Refresh the window of preview InvokeRefreshPreview();
VB
'Create a page Dim Page As New StiPage 'Load the page from a file Page.Load("MyPage.pg") 'Add a page to the collection of rendered pages Report.RenderedPages.Add(Page) 'Refresh the window of preview Report.InvokeRefreshPreview()
使用報(bào)表生成器的InvokeRefreshPreview方法:
C#
this.InvokeRefreshPreview();
VB
Me.InvokeRefreshPreview()
使用報(bào)表的RenderedPages屬性:
C#
foreach (StiPage page in report.RenderedPages) { }
VB
Dim page As StiPage For Each page In MyBase.RenderedPages Next
使用Printable屬性:
創(chuàng)建或新增一個(gè)組件:
C#
StiImage image = new StiImage(); image.Left = 0; image.Top = 0; image.Width = 10; image.Height = 10; //An image name should be unique in your report image.Name = "MyUniqueName"; //Assign an image image.Image = myImage; //Add a component with an image with a report report.Pages[0].Components.Add(image);
VB
Dim Image As StiImage = New StiImage() Image.Left = 0 Image.Top = 0 Image.Width = 10 Image.Height = 10 'An image name should be unique in your report Image.Name = "MyUniqueName" 'Assign an image Image.Image = myImage 'Add a component with an image with a report Report.Pages(0).Components.Add(Image)
如果報(bào)表已經(jīng)從程序集中編譯或加載,替換圖像需要使用ImageToDraw屬性。
修改報(bào)表中的圖像有兩種方法:
第一種-報(bào)表還沒(méi)被編譯
在報(bào)表中找到包含圖像的組件:
C#
StiImage image = report.GetComponents()["image1"] as StiImage;
VB
Dim Image As StiImage = CType(Report.GetComponents()("image1"), StiImage)
修改圖像:
C#
image.Image = myImage;
VB
Image.Image = MyImage
這種方法,你的圖像你的圖像被轉(zhuǎn)換成代碼,然后報(bào)表回編譯且運(yùn)行它。
第二種-報(bào)表從程序集中加載且編譯過(guò)
編譯報(bào)表
C#
report.Compile();
VB
Report.Compile()
找到組件
C#
StiImage image = report.GetComponents()["image1"] as StiImage;
VB
Dim Image As StiImage = CType(Report.GetComponents()("image1"), StiImage)
指定圖像:
C#
image.ImageToDraw = myImage;
VB
Image.ImageToDraw = MyImage
使用報(bào)表的IsStopped屬性:
C#
if (!report.IsStopped)
使用報(bào)表的Rendering事件。示例如下:
C#
//Create a new report StiReport report = new StiReport(); report.Load("report.mrt"); //Compile this report by all means report.Compile(); //Add to the Rendering event of a compiled report report.CompiledReport.Rendering += new EventHandler(this.OnRendering); //Start report rendering. Attention! The Render method is called from False arguments. //This argument indicates that there is no need to show progress of report rendering report.Render(false); //Show the rendered report report.Show(); //The event which we are attaching private void OnRendering(object sender, EventArgs e) { StiReport report = sender as StiReport; string info = (report.PageNumber -1).ToString(); }
VB
'Create a new report Dim Report As New StiReport Report.Load("report.mrt") 'Compile this report by all means Report.Compile() 'Add to the Rendering event of a compiled report AddHandler Report.CompiledReport.Rendering, New EventHandler(AddressOf Me.OnRendering) 'Start report rendering. Attention! The Render method is called from False arguments. 'This argument indicates that there is no need to show progress of report rendering Report.Render(False) 'Show the rendered report Report.Show() 'The event which we are attaching Private Sub OnRendering(ByVal sender As Object, ByVal e As EventArgs) Dim Report As StiReport = CType(sender, StiReport) Dim Info As String = (Report.PageNumber -1).ToString() End Sub
注意!你必須附加到report.CompiledReport,只有這樣才能運(yùn)行Compile方法。
購(gòu)買最新正版授權(quán)!""
慧都年終盛典火爆開啟,一年僅一次的最強(qiáng)促銷,破冰鉅惠不容錯(cuò)過(guò)??!優(yōu)惠詳情點(diǎn)擊查看>>
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn