Stimulsoft Reports.WPF教程:Designer中的自定义组件

发布时间 : 2018-09-19 10:38:14.000|阅读 638 次

概述:本文主要介绍Stimulsoft报表Designer中的自定义组件。

相关链接:

【下载Stimulsoft Reports.WPF最新版本】

此示例显示如何将自定义组件添加到Designer。为此,您应该创建自定义组件的新类。例如,创建从StiComponent继承的MyCustomComponent类。还要为新组件定义BorderBrush属性:

[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

下载示例

购买Stimulsoft正版授权,请点击“咨询在线客服”哟!

FastReport2018.4


在线
客服
微信
QQ 电话
023-68661681
返回
顶部