开发者

how to change the color of all the textbox avaliable in Asp.net Window Application?

I would like to change the all the textbox c开发者_JS百科olor in the c# Window Application on click on button.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜