翻譯|使用教程|編輯:王香|2018-09-19 10:38:14.000|閱讀 734 次
概述:本文主要介紹Stimulsoft報表Designer中的自定義組件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載Stimulsoft Reports.WPF最新版本】
此示例顯示如何將自定義組件添加到Designer。為此,您應該創建自定義組件的新類。例如,創建從StiComponent繼承的MyCustomComponent類。還要為新組件定義Border和Brush屬性:
[StiToolbox(true)] [StiContextTool(typeof(IStiShift))] [StiContextTool(typeof(IStiGrowToHeight))] [StiV1Builder(typeof(MyCustomComponentV1Builder))] [StiV2Builder(typeof(MyCustomComponentV2Builder))] [StiWpfPainter(typeof(MyCustomComponentWpfPainter))] public class MyCustomComponent : StiComponent, IStiBorder, IStiBrush { #region StiComponent override ////// Gets value to sort a position in the toolbox. ///public override int ToolboxPosition { get { return 500; } } public override StiToolboxCategory ToolboxCategory { get { return StiToolboxCategory.Components; } } ////// Gets a localized name of the component category. ///public override string LocalizedCategory { get { return StiLocalization.Get("Report", "Components"); } } ////// Gets a localized component name. ///public override string LocalizedName { get { return "MyCustomComponent1"; } } #endregion #region IStiBorder private StiBorder border = new StiBorder(); ////// Gets or sets frame of the component. ///[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); ////// Gets or sets a brush to fill a component. ///[StiCategory("Appearance")] [StiSerializable] [Description("Gets or sets a brush to fill a component.")] public StiBrush Brush { get { return brush; } set { brush = value; } } #endregion #region this ////// Creates a new component of the type MyCustomComponent. ///public MyCustomComponent() : this(RectangleD.Empty) { } ////// Creates a new component of the type MyCustomComponent. //////The rectangle describes size and position of the component.public MyCustomComponent(RectangleD rect) : base(rect) { PlaceOnToolbox = true; } #endregion }
要將自定義組件添加到Designer工具箱,只需向StiConfig.Services集合添加一個類。此外,應將此類添加到StiConfig.Engine集合中,以識別報表引擎:
public Window1() { StiOptions.Wpf.CurrentTheme = StiOptions.Wpf.Themes.Office2013Theme; InitializeComponent(); AddCustomComponent(); } 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.Base.Dll", "Stimulsoft.Report.Dll", #region Add reference to your assembly "CustomComponent.Wpf.exe" #endregion }; StiConfig.Services.Add(new MyCustomComponent()); StiConfig.Save(); }
示例代碼的結果如下圖所示:
購買Stimulsoft正版授權,請點擊“”喲!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn