禁用编辑自定义DevComponents.DotNetBar控件的子控件

时间:2012-08-26 13:42:05

标签: c# winforms custom-controls design-time dotnetbar

我创建了一个新的自定义控件,继承自Bar controlDevComponents.DotNetBar个控件。接下来,我在其中创建了一个新的dock选项卡,并将其他控件添加到其中。

编译自定义控件并在新的Windows窗体中添加创建的自定义控件后,Dock选项卡控件在设计时可编辑。

我不希望任何人在设计时编辑这些控件(Dock Tab Controls)。如何在设计时禁止从表单编辑控件(与编辑控件本身不同)?

public partial class barFloorsGrouping : Bar
{
    public barFloorsGrouping()
    {
        InitializeComponent();
    }

    [ReadOnly(true)]
    public new System.Windows.Forms.AccessibleRole AccessibleRole
    {
        get { return base.AccessibleRole; }
        private set { base.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool AlwaysDisplayDockTab
    {
        get { return base.AlwaysDisplayDockTab; }
        private set { base.AlwaysDisplayDockTab = true; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool AlwaysDisplayKeyAccelerators
    {
        get { return base.AlwaysDisplayKeyAccelerators; }
        private set { base.AlwaysDisplayKeyAccelerators = true; }
    }

    [ReadOnly(true)]
    public new bool AntiAlias
    {
        get { return base.AntiAlias; }
        private set { base.AntiAlias = true; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool AutoCreateCaptionMenu
    {
        get { return base.AutoCreateCaptionMenu; }
    }

    [ReadOnly(true)]
    public new bool AutoHide
    {
        get { return base.AutoHide; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool AutoHideTabTextAlwaysVisible
    {
        get { return base.AutoHideTabTextAlwaysVisible; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool AutoSyncBarCaption
    {
        get { return base.AutoSyncBarCaption; }
        private set { base.AutoSyncBarCaption = true; }
    }

    [Browsable(false), ReadOnly(true)]
    public new eBarType BarType
    {
        get { return base.BarType; }
        private set { base.BarType = eBarType.DockWindow; }
    }

    [ReadOnly(true)]
    public new bool CanAutoHide
    {
        get { return base.CanAutoHide; }
    }

    [ReadOnly(true)]
    public new bool CanDockTab
    {
        get { return base.CanDockTab; }
        private set { base.CanDockTab = false; }
    }

    [ReadOnly(true)]
    public new bool CanUndock
    {
        get { return base.CanUndock; }
        private set { base.CanUndock = false; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool CloseSingleTab
    {
        get { return base.CloseSingleTab; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool DisplayMoreItemsOnMenu
    {
        get { return base.DisplayMoreItemsOnMenu; }
        private set { base.DisplayMoreItemsOnMenu = true; }
    }

    [ReadOnly(true)]
    public new DockStyle Dock
    {
        get { return base.Dock; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool DockTabCloseButtonVisible
    {
        get { return base.DockTabCloseButtonVisible; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool FadeEffect
    {
        get { return base.FadeEffect; }
        private set { base.FadeEffect = true; }
    }

    [Browsable(false), ReadOnly(true)]
    public new eGrabHandleStyle GrabHandleStyle
    {
        get { return base.GrabHandleStyle; }
        private set { base.GrabHandleStyle = eGrabHandleStyle.Caption; }
    }

    [Browsable(false), ReadOnly(true)]
    public new eLayoutType LayoutType
    {
        get { return base.LayoutType; }
        private set { base.LayoutType = eLayoutType.DockContainer; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool MenuBar
    {
        get { return base.MenuBar; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool TabNavigation
    {
        get { return base.TabNavigation; }
        private set { base.TabNavigation = true; }
    }

    [Browsable(false), ReadOnly(true)]
    public new bool WrapItemsDock
    {
        get { return base.WrapItemsDock; }
        private set { base.WrapItemsDock = true; }
    }

    protected override void OnPaint(PaintEventArgs pe)
    {
        base.OnPaint(pe);
    }
}

2 个答案:

答案 0 :(得分:0)

您必须使用 ParentControlDesigner 类扩展设计模式行为。 ParentControlDesigner类为可以包含子控件的控件的设计者提供基类。

因此,要实现目标,您必须通过 DesignerAttribute 实现组件的设计时服务,如下所示(只需在编写的类之前添加以下代码):

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
public partial class barFloorsGrouping : Bar
{
...
}

答案 1 :(得分:-1)

编辑:一如既往,我在asp.net和webforms工作......这个答案适用于WebForms

您需要覆盖WebControl的GetDesignTimeHtml。

请参阅MSDN docs

听起来我没有做过很多服务器控件创建,所以你可以获得很多乐趣......