【Stimulsoft Reports.WPF教程】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
    /// <summary>
    /// Gets value to sort a position in the toolbox.
    /// </summary>
    public override int ToolboxPosition
    {
        get
        {
            return 500;
        }
    }
 
    public override StiToolboxCategory ToolboxCategory
    {
        get
        {
            return StiToolboxCategory.Components;
        }
    }
 
    /// <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
 
    #region IStiBorder
    private StiBorder border = new StiBorder();
    /// <summary>
    /// Gets or sets 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
 
    #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
}

要将自定义组件添加到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

查看原文,下载示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值