i have a System.Windows.Forms.Panel control in a windows application that has many labels and textboxes within the panel. When you call the Panel.Enabled = false command all of the textboxes and labels go gray and become un-editable which is the desired effect. Is there a way to overload the light gray colors when the panel is disabled?
Solution used:
Since the disabled color cant be overiden when disabled the following was used to disable only text boxes and labels on the Panel rather than the blanked Panel.Enabled = false;.
//Loop through the Member info Panel and find all the group boxes foreach (Control cItem in Panel.Controls) { //A group box is found if (cItem is GroupBox) { //Loop through all the group box components foreach (Control cSubItem in cItem.Controls) { //If its a label of text box disable it if (cSubItem is TextBox || cSubItem is Label) { cSubItem.Enabled = false; } } } }
As an alternative: If the controls you wish to have a different enabled/disabled color you could iterate through the controls registered with the panel and assign their EnabledChanged event a custom function to change their color (based on type I assume). You’d probably want to filter the type of control you modify with this but you could use this to achieve your goal I believe.
Update: Try this:
public void deselected(object sender, EventArgs e) { foreach (Control c in this.Controls) { //TODO:check type of control and change background color } }That will need to be placed inside your Form class but then you can use it on a event. Hope that helps.