How to disable all control inside a form ?
-
i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?
Regards, Chee ken
for each (Control control in Controls) control.Enabled = false end for I don't 'do' VB, the syntax may be off. However, there is a Controls collection in your form that you can foreach over.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?
Regards, Chee ken
-
for each c as Control in me.controls if typeof c is textbox then 'for textbox you can put label or whatever other controls 'do actions (e.g. c.enabled = false) end if next
Posted by The ANZAC
If Not cbYear.SelectedValue.Equals(Now.Year.ToString) Then ' Examine every control. For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = False On Error GoTo 0 End If Next ctl Else For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = True On Error GoTo 0 End If Next ctl End If cbYear is a combobox, why this code cannot work ? If i comment " If TypeOf ctl Is TextBox Then" then all control will disable. thanks
Regards, Chee ken
-
i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?
Regards, Chee ken
or you can put them in a GroupBox and, set GroupBox's enable property to false
Chatura Dilan
-
or you can put them in a GroupBox and, set GroupBox's enable property to false
Chatura Dilan
Same for a
Panel
.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?
Regards, Chee ken
-
If Not cbYear.SelectedValue.Equals(Now.Year.ToString) Then ' Examine every control. For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = False On Error GoTo 0 End If Next ctl Else For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = True On Error GoTo 0 End If Next ctl End If cbYear is a combobox, why this code cannot work ? If i comment " If TypeOf ctl Is TextBox Then" then all control will disable. thanks
Regards, Chee ken