翻譯|使用教程|編輯:王香|2018-08-17 11:47:34.000|閱讀 1559 次
概述:本文主要講解如何在Stimulsoft Report中將自定義組件添加到報表設計器
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載Stimulsoft Reports.Ultimate最新版本】
此示例顯示如何創建自定義組件并將其添加到報表設計器。自定義組件提供了在報表設計器中添加帶有參數的組件并在報表中使用它的功能。例如,您可以添加stimulsoft報表中不存在的圖表。
首先,指定屬性及其值:
[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))] ...
接下來,創建一個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(邊框和畫筆),并設置其默認值:
... #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 ...
將必要的構造函數添加到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收集,現在我們可以在報表設計器工具欄中找到它:
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(); }
示例代碼的結果如下圖所示:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn