Dear Frieds,
I have a problem, here it is....
When you want to lock controls in the window form, What is the coding for that?
Because, there I want to lock all controls in the window form when form is loading and only allow to view data through the window form. And then When you click on the Edit button or Add New button only that all the controls can be unlocked.
So, How do you lock text boxes?

Scott LysleRank #49 · 31K reputationPosted Apr 29, 2008, 5:58 AM EDT
Ryan AlfordRank #1,411 · 1.2K reputationPosted Apr 29, 2008, 6:04 AM EDT
foreach(Control c in this.Controls)
{
c.Enabled = false;
}
then you will need to enable any buttons that you want enabled. then do the opposite when they click one of those enabled buttons.
AlanRank #669 · 3.6K reputationPosted Apr 29, 2008, 8:10 AM EDT
To lock textboxes specifically, you can also set their ReadOnly properties to true either individually or in a loop as in Ryan's code:
foreach(Control c in this.Controls)
{
if (c is TextBox)
{
TextBox tb = (TextBox)c;
tb.ReadOnly = true;
}
}