禁用编辑自定义DevComponents.DotNetBar控件的子控件 [英] Disable editing child controls of custom DevComponents.DotNetBar control

查看:78
本文介绍了禁用编辑自定义DevComponents.DotNetBar控件的子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的自定义控件,该控件继承自DevComponents.DotNetBar控件的Bar控件.接下来,我在其中创建了一个新的Dock选项卡,并向其中添加了其他控件.
编译自定义控件并将创建的自定义控件添加到新的Windows窗体中之后,Dock选项卡控件在设计时就可以编辑.
我不希望任何人都可以在设计时编辑这些控件(Dock选项卡控件).如何在设计时从表单禁用编辑控件(与编辑控件本身不同)?

I have created a new Custom Control inheriting from Bar control of DevComponents.DotNetBar controls. Next, I have created a new dock tab in it and have added my other controls to it.
After I compile my Custom Control and add my created Custom Control in a new Windows Form, Dock Tab Controls are editable at design time.
I don''t want that anybody can edit these controls (Dock Tab Controls) in design time. How can I disable editing the controls at design time from the form (not the same as editing the control itself)?

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);
    }
}

推荐答案

假设您不在Silverlight或WPF中,则可以检查Component.DesignMode属性 [
Assuming you are not in Silverlight or WPF, you can check for the Component.DesignMode Property[^] - you need to do this recursively using the Parent property for the control.

Best regards
Espen Harlinn


您必须使用 ParentControlDesigner 类扩展设计模式的行为. ParentControlDesigner类为可以包含子控件的控件设计者提供了一个基类.
因此,为了实现您的目标,您必须通过 DesignerAttribute 为组件实现设计时服务,如下所示(只需在编写的类之前添加以下代码):

You must extend the design mode behavior by using ParentControlDesigner Class. ParentControlDesigner Class provides a base class for designers of controls that can contain child controls.
So, for achieve to your Goal, you must implement design-time services for a component by DesignerAttribute as the following (Just add below code before the written class):

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


只需定义bool属性并在自动创建控件的方法的开头添加条件.

Just define a bool property and add a condition at beginning of the method that creates controls automatically.

bool AllowCreate;


public void Do()
{
    if (AllowCreate)
    {
        // your code to create controls
    }
}


这篇关于禁用编辑自定义DevComponents.DotNetBar控件的子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆