Reputation: 141
I have user_control with 1 textbox and a button. I want to override the Enabled property of the control in such a way, retain the button always enabled and enable / disable of the control only affect the textbox.
How can i archive it? Thanks in advance.
Edited : I think my question may not be clear. Actually I have overrides the Enabled property as follows,
Private m_Enabled As Boolean
Public Overloads Property Enabled() As Boolean
Get
Return m_Enabled
End Get
Set(ByVal value As Boolean)
Button1.Enabled = True
TextBox1.Enabled = value
m_Enabled = value
End Set
End Property
I have place this usercontrol and few other textboxs in a Panel1. I try to loop through the controls one by one and disable it.
For Each panelControl As Control In Panel1.Controls
panelControl.Enabled = False
Next panelControl
This enabled property never called in this case. (whole control get disabled / enabled)
Can someone help me?
Upvotes: 0
Views: 1385
Reputation: 81635
The problem is your cast: For Each panelControl As Control
which will use the control's enabled property, not your overload.
Try casting instead:
For Each ctrl As UserControl1 In Panel2.Controls.OfType(Of UserControl1)()
ctrl.Enabled = False
Next
Upvotes: 1