原創(chuàng)|使用教程|編輯:鄭恭琳|2015-12-18 11:21:17.000|閱讀 2210 次
概述:本片文章主要介紹Stimulsoft Reports.Net開發(fā)者在預覽報表時遇到的常見問題及解決方案。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
< Stimulsoft Reports.Net v2015.3最新版本下載>
使用StiViewerControl類的靜態(tài)事件SavingDocument和LoadingDocument。SavingDocument用來保存已渲染的報表,LoadingDocument用來加載已渲染的報表。
保存已渲染的報表處理方法如下:
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)
加載已渲染報表的處理方法如下:
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)
要想去掉預覽窗口中的按鈕,你需要修改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也可以得到相同的結果。此外你還可以使用StiPreviewControl,它包含許多用來控制預覽窗口中控件可見性的屬性。你還可以在報表設計器里修改PreviewSettings屬性實現(xiàn)。
使用StiPreviewControl可以關閉工具欄,將ShowToolbar的屬性設置為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()
你的報表預覽窗口需要有接收報表輸入對象的構造函數(shù)。然后使用報表類的PreviewForm屬性,該屬性有Type類型。換句話說你的報表預覽窗口將被第一個創(chuàng)建并顯示出來。
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)
使用縮放設置的預定義方法:
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()
使用報表生成器的InvokeRefreshPreview方法:
C#
this.InvokeRefreshPreview();
VB
Me.InvokeRefreshPreview()
使用報表的RenderedPages屬性:
C#
foreach (StiPage page in report.RenderedPages) { }
VB
Dim page As StiPage For Each page In MyBase.RenderedPages Next
使用Printable屬性:
創(chuàng)建或新增一個組件:
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)
如果報表已經從程序集中編譯或加載,替換圖像需要使用ImageToDraw屬性。
修改報表中的圖像有兩種方法:
第一種-報表還沒被編譯
在報表中找到包含圖像的組件:
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
這種方法,你的圖像你的圖像被轉換成代碼,然后報表回編譯且運行它。
第二種-報表從程序集中加載且編譯過
編譯報表
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
使用報表的IsStopped屬性:
C#
if (!report.IsStopped)
使用報表的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,只有這樣才能運行Compile方法。
購買最新正版授權!""
慧都年終盛典火爆開啟,一年僅一次的最強促銷,破冰鉅惠不容錯過!!優(yōu)惠詳情點擊查看>>
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn