Textbox forecolor == "window" for non selected controls
I'm trying to do something with the textbox control, I want that all controls take the color "window" (which I already set to it in properties). It works but only 开发者_开发问答for the current selected control, I want all controls with the "window" color all time.
How can I do this
From what I understand, you have a variable of type color named window and you want to programmatically set all of the controls to that color.
foreach( Control myControl in this.Controls)
{
myControl.BackColor = window;
}
That does the trick, assuming you've added the controls to the "Controls" collection in the form.
EDIT: Alternatively, if you want just the textboxes to change, you can always use this if statement around the assignment
if (myControl.GetType()==typeof(System.Windows.Forms.TextBox))
精彩评论