ElektroStudios
ElektroStudios

Reputation: 20464

ReadOnly Property with IF statement

I'm trying to create a inherited control. I made a boolean public property for this control titled "Flickering" to enable/disable the flickering effects on the control.

Then what I want is to "turn on" the next overridable property only when the "Flickering" property is enabled, but I don't have idea of how to do this:

Protected Overrides ReadOnly Property CreateParams() As CreateParams
If Disable_Flickering = True Then
    Get
        Dim cp As CreateParams = MyBase.CreateParams
        cp.ExStyle = cp.ExStyle Or &H2000000
        Return cp
    End Get 
End If
End Property

The code obviously does not work but also I think I'm not thinking in the correct logic to do this.

How I can do it?

ANSWER:

''' <summary>
''' Enable/Disable any flickering effect on the panel.
''' </summary>
Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        If _Diable_Flickering Then
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or &H2000000
            Return cp
        Else
            Return MyBase.CreateParams
        End If
    End Get
End Property

Upvotes: 1

Views: 266

Answers (1)

Felice Pollano
Felice Pollano

Reputation: 33242

It is not possible to have a property conditionally visible. You can alternatively throw an exception if someone try to change or get the value when the object is in an inappropriate state.

Upvotes: 6

Related Questions