1

I would like to change the all the textbox color in the c# Window Application on click on button.

AB Vyas
  • 2,349
  • 6
  • 26
  • 43

2 Answers2

0

loop all the controls using for each statement, then check the type of control if textbox then set its BackgroundColor.

Deepesh
  • 5,346
  • 6
  • 30
  • 45
  • But all the Textbox controls are not in one form. all the textbox are in different form – AB Vyas Jun 01 '11 at 09:39
  • 1
    In WPF app you can use theme and at runtime you can change the themes for whole app. I think that can be a feasible solution in your case – Deepesh Jun 01 '11 at 09:49
0

The following function iterates all controls in the current Windows.Forms.Form. If the current control is a text box control, it sets its backcolor to red:

foreach (Control c in Controls)
{
    TextBox tb = c as TextBox;
    if (tb != null)
    {
        tb.BackColor = System.Drawing.Color.Red; 
    }
}

Edit: the question seemed to be changed from ASP.NET -> Windows application. Now we iterate the Controls collection of the current Windows.Forms.Form.

Edit2: since the question now changes to WPF: you may use the information in this SO question here, to retrieve all open windows in the application.

Community
  • 1
  • 1
user492238
  • 4,094
  • 1
  • 20
  • 26
  • This can be change color of only one form controls i would like to in all the form which are avaliable in application – AB Vyas Jun 01 '11 at 09:42