Conditional Property in Design-Time

MarcosMendes

New member
Joined
Oct 11, 2016
Messages
1
Programming Experience
10+
Hi friends,




I'm developing a C # component that inherits from TextBox. A simple component, with validations and masks only.



The problem is that I have a Data Type property, with several possible attributes (CPF, CNPJ, RG, Voter Title, and others) and the General attribute that is used case of the programmer does not want to enable validations or masks. In this case, the component would behave like a normal TextBox, only with extra component design options.


Thus, I would like the Boolean Validation and Mask properties to be disabled [Enable (false)] for the General Data Type property, but to be enabled [Enable (true)] for the other options ...



I've never worked with design-time development before so I have no many idea how I can do it.

I'm attaching an image that may help you understand what I'm needing.


In it the Mask property is enabled for change. What I need is that it is not enabled, unless the Data Type property has an attribute other than General.

I tried to create the interface, the below, for the Validation property (which has the same scope and must have the same Mask behavior (I have not put it in the Interface yet, it is outside, according to the code), but that way, the Validation property does not appear in the properties panel as you can see in the attached image.


C#:
#region TESTES
        
        public interface IReadOnlyProperties
        {
            bool ValidationPropertie { get; set; }
        }


        public class IsReadOnly : IReadOnlyProperties
        {
            private bool _validationStatus;
            [ReadOnly(true)]
            [Browsable(true)]
            [DisplayName("Validation")]
            [DefaultValue(false)]


            public bool ValidationPropertie
            {
                get { return _validationStatus; }
                set { _validationStatus = value; }
            }
            //public bool ValidationPropertie { get; set; }
        }


        public class IsNotReadOnly : IReadOnlyProperties
        {
            private bool _validationStatus;


            [ReadOnly(false)]
            [Browsable(true)]
            [DisplayName("Validation")]
            [DefaultValue(false)]


            public bool ValidationPropertie
            {
                get { return _validationStatus; }
                set { _validationStatus = value; }
            }
            //public bool ValidationPropertie { get; set; }


        }


        public void TESTE()
        {
            MessageBox.Show("Entrou em Teste");


            IReadOnlyProperties instance = null;
            if (DataType != myT_TextBox_Component._DataType.Geral)
            {
                instance = new IsReadOnly();
            }
            else
            {
                instance = new IsNotReadOnly();
            }


        }


        #endregion TESTES


C#:
[B]​[/B]


private bool _maskStatus;


            [Browsable(true)]
            [DisplayName("Mask")]
            [DefaultValue(false)]
            public bool MaskPropertie
            {
                get { return _maskStatus; }
                set { _maskStatus = value; }
            }
 

Attachments

  • Sem Título-4.jpg
    Sem Título-4.jpg
    66.3 KB · Views: 88
Back
Top Bottom