Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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);
    }
}
Posted 26-Aug-12 2:28am
MRS1989618
Edited 28-Aug-12 4:35am
v10
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
{
...
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Mohsen Rostami at 26-Aug-12 11:39am
   
Can you explain that? I'm not very familiar with manipulating controls.
Mika Wendelius at 26-Aug-12 17:22pm
   
To Espen: Good advice, 5'ed. I actually wrote a small tip about this and how the DesignMode can be resolved from outside the control (since it's protected). If you want to have a look, its <a href="http://www.codeproject.com/Tips/447319/Resolve-DesignMode-for-a-user-control">Resolve DesignMode for a user control</a>[<a title="New Window" href="http://www.codeproject.com/Tips/447319/Resolve-DesignMode-for-a-user-control" target="_blank">^</a>]. If you want to make changes etc. to it. I'd be more than happy to add you as a co-author.
Mohsen Rostami at 27-Aug-12 0:27am
   
Thanks for your comment. It was useful for me but was irrelevant to my problem. My problem is disabling child controls of a custom control that are enabled by default. I don't want that user can select it, see their properties and change them. You explain that how can understand a control (include UserControl or CustomControl) is in design mode or not. I know about it. However, I want that prevent from select automatically created child controls by other users. Thank you in advance for any help.
Mika Wendelius at 27-Aug-12 0:33am
   
Thanks for the comment. Yes I noticed that this is a different situation, but it was just giving the idea for a small tip :)
Mohsen Rostami at 27-Aug-12 3:13am
   
So, U can help me???
Mika Wendelius at 27-Aug-12 3:30am
   
If I understood you correctly, could you simply use the same mechanism and travel through the parents and their properties and see if any of the parent controls is disabled etc? Since this is Espen's answer, I'd prefer him modifying it suitable to your needs.
Mohsen Rostami at 27-Aug-12 3:39am
   
I want to disable child controls as never work and remain inactive/disable in Design mode and only enable in running mode. Because nobody can access to their properties and change them.
Espen Harlinn at 27-Aug-12 4:09am
   
If DesignMode is true for your user control, or any of its Parent controls, then you are running under the designer.
Mohsen Rostami at 27-Aug-12 4:16am
   
Ok. Can explain more? Can I send my example code to you? After you see that, you know that I exactly want what.
Espen Harlinn at 27-Aug-12 4:28am
   
Use someting like this to determine whether you are running under the designer or not: bool InDesigner() { Control ctrl = this; while(ctrl != null) { if( ctrl.DesignMode ) { return true; } ctrl = ctrl.Parent; } return false; }
Mohsen Rostami at 27-Aug-12 4:35am
   
So, I know it. However, I want that automatically created child controls can be seen by other users in design mode, but they can't select it and can't access to their properties for change them. I want that they are inactive/disable in design mode and enable/active in running mode.
Espen Harlinn at 27-Aug-12 4:40am
   
override the OnParentChanged http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onparentchanged.aspx for your user control and and enable or disable controls as you like.
Mohsen Rostami at 27-Aug-12 4:49am
   
I hope that it's worked for me. Thank you in advance for any help.
Mohsen Rostami at 27-Aug-12 5:09am
   
It's not done what I need. Can send my codes to you???
Mohsen Rostami at 27-Aug-12 5:19am
   
Changing Enabled Attribute can't prevent access other users to properties of the control. It only changes Visual State that works in Running time not in Design time. I want a solution that can prevent access other users to its properties and prevent from select it in design time.
Espen Harlinn at 27-Aug-12 4:28am
   
Thank you, Mika :-D
Marcus Kramer at 28-Aug-12 9:26am
   
+5. I didn't quite get the question until I read your answer for this one.
Espen Harlinn at 28-Aug-12 9:27am
   
Thank you, Marcus :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
    }
}
  Permalink  
Comments
Mohsen Rostami at 26-Aug-12 11:48am
   
My problem is in design architect. Espen Harlinn is understood right my problem; however, I'm new to this subject of programming in C#.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 756
1 OriginalGriff 452
2 Tadit Dash 350
3 sanket saxena 329
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid