I would like to change the all the textbox color in the c# Window Application on click on button.
Asked
Active
Viewed 2,372 times
1
-
2What do you mean by Asp.Net Windows application? Is it an intranet application, a wpf application using the browser control, a normal web application using .Net? – Yet Another Geek Jun 01 '11 at 09:36
-
yes that is one type of WPF Application – AB Vyas Jun 01 '11 at 09:37
-
Please tell us, is this asp.net web or windows application? – Muhammad Akhtar Jun 01 '11 at 09:38
-
@Muhammad Akhtar: Window Application – AB Vyas Jun 01 '11 at 09:40
2 Answers
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
-
1In 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