翻譯|使用教程|編輯:王香|2018-08-17 11:47:34.000|閱讀 1559 次
概述:本文主要講解如何在Stimulsoft Report中將自定義組件添加到報(bào)表設(shè)計(jì)器
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
【下載Stimulsoft Reports.Ultimate最新版本】
此示例顯示如何創(chuàng)建自定義組件并將其添加到報(bào)表設(shè)計(jì)器。自定義組件提供了在報(bào)表設(shè)計(jì)器中添加帶有參數(shù)的組件并在報(bào)表中使用它的功能。例如,您可以添加stimulsoft報(bào)表中不存在的圖表。
首先,指定屬性及其值:
[StiServiceBitmap(typeof(MyCustomComponent), "CustomComponent.MyCustomComponent1.gif")] [StiToolbox(true)] [StiContextTool(typeof(IStiShift))] [StiContextTool(typeof(IStiGrowToHeight))] [StiDesigner(typeof(MyCustomComponentDesigner))] [StiV1Builder(typeof(MyCustomComponentV1Builder))] [StiV2Builder(typeof(MyCustomComponentV2Builder))] [StiGdiPainter(typeof(MyCustomComponentGdiPainter))] ...
接下來(lái),創(chuàng)建一個(gè)MyCustomComponent類并指定繼承的類。此外,覆蓋必需的組件屬性:
... public class MyCustomComponent : StiComponent, IStiBorder, IStiBrush { #region StiComponent override /// <summary> /// Gets value to sort a position in the toolbox. /// </summary> public override int ToolboxPosition { get { return 500; } } /// <summary> /// Gets a localized name of the component category. /// </summary> public override string LocalizedCategory { get { return StiLocalization.Get("Report", "Components"); } } /// <summary> /// Gets a localized component name. /// </summary> public override string LocalizedName { get { return "MyCustomComponent1"; } } #endregion ...
向組件添加新屬性——Border and Brush(邊框和畫筆),并設(shè)置其默認(rèn)值:
... #region IStiBorder private StiBorder border = new StiBorder(); /// <summary> /// Gets or sets a frame of the component. /// </summary> [StiCategory("Appearance")] [StiSerializable] [Description("Gets or sets frame of the component.")] public StiBorder Border { get { return border; } set { border = value; } } #endregion #region IStiBrush private StiBrush brush = new StiSolidBrush(Color.Transparent); /// <summary> /// Gets or sets a brush to fill a component. /// </summary> [StiCategory("Appearance")] [StiSerializable] [Description("Gets or sets a brush to fill a component.")] public StiBrush Brush { get { return brush; } set { brush = value; } } #endregion ...
將必要的構(gòu)造函數(shù)添加到MyCustomComponent類型的新組件:
... #region this /// <summary> /// Creates a new component of the type MyCustomComponent. /// </summary> public MyCustomComponent() : this(RectangleD.Empty) { } /// <summary> /// Creates a new component of the type MyCustomComponent. /// </summary> /// <param name="rect">The rectangle describes size and position of the component.</param> public MyCustomComponent(RectangleD rect) : base(rect) { PlaceOnToolbox = true; } #endregion }
該AddCustomComponent方法添加自定義組件的StiConfig.Services收集,現(xiàn)在我們可以在報(bào)表設(shè)計(jì)器工具欄中找到它:
private static void AddCustomComponent() { StiConfig.Load(); StiOptions.Engine.ReferencedAssemblies = new string[]{ "System.Dll", "System.Drawing.Dll", "System.Windows.Forms.Dll", "System.Data.Dll", "System.Xml.Dll", "Stimulsoft.Controls.Dll", "Stimulsoft.Base.Dll", "Stimulsoft.Report.Dll", #region Add reference to your assembly "CustomComponent.exe" #endregion }; StiConfig.Services.Add(new MyCustomComponent()); StiConfig.Services.Add(new MyCustomComponentWithDataSource()); StiConfig.Services.Add(new MyCustomComponentWithExpression()); StiConfig.Save(); }
示例代碼的結(jié)果如下圖所示:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn