// This might be called from a thread other than the control's UI thread private void UpdateTheme() { if (_extendedControls.Count == 0) { return; } Control c = _extendedControls[0]; if (c.InvokeRequired) { // assume all contros are on the same form / same UI thread c.Invoke(new MethodInvoker(UpdateTheme)); return; } Color backColor = _styleManager.GetThemeColor("*.BackColor.*"); Color foreColorNormal = _styleManager.GetThemeColor("*.ForeColor.Normal"); Color foreColorDisabled = _styleManager.GetThemeColor("*.ForeColor.Disabled"); foreach (Control ctrl in _extendedControls) { try { if (ctrl.BackColor != backColor) { ctrl.BackColor = backColor; } } catch { } try { Color col = ctrl.Enabled ? foreColorNormal : foreColorDisabled; if (ctrl.ForeColor != col) { ctrl.ForeColor = col; } } catch { } } }
protected virtual Color GetThemeColor(string property) { return(_styleManager.GetThemeColor(property, MetroControlState, MetroControlCategory)); }