public void SetTheme(string themeName) { currentTheme = themeName; ThemeData td = allThemes.ThemesList.Single(w => w.ThemeName == currentTheme); ModifyControls(td); }
private void ModifyControls(ThemeData td) { foreach (var item in td.Ctrl) { if (item.ControlName == "Form") { clientForm.BackColor = item.BackColor; continue; } string fullControlName = "System.Windows.Forms" + "." + item.ControlName + ", System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; Type controlType = Type.GetType(fullControlName); List <PropertyInfo> propertyList = item.GetType().GetProperties().ToList(); foreach (Control currentControl in clientForm.Controls) { #region childControls if (currentControl.HasChildren) { foreach (Control groupBoxControl in currentControl.Controls) { if (groupBoxControl.Tag != null) { continue; } if (groupBoxControl.GetType() == controlType) { foreach (PropertyInfo property in propertyList.Skip(1)) { PropertyInfo PI = controlType.GetProperty(property.Name); PI?.SetValue(groupBoxControl, property.GetValue(item)); } } } } if (currentControl.Tag != null) { continue; } #endregion if (currentControl.GetType() == controlType) { foreach (PropertyInfo property in propertyList.Skip(1)) { PropertyInfo PI = controlType.GetProperty(property.Name); PI?.SetValue(currentControl, property.GetValue(item)); } } } } }