/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the color object information for the specified component. /// </summary> /// ------------------------------------------------------------------------------------ private ColorOverrideInfo GetComponentInfo(IComponent component) { ColorOverrideInfo coi; if (!_extendedCtrls.TryGetValue(component, out coi)) { _extendedCtrls[component] = coi = new ColorOverrideInfo(UsePaletteColorsForComponent(component)); } return(coi); }
private void ApplyColorChange(object component, ColorOverrideInfo info) { var control = component as Control; if (control != null) { bool resetUseVisualStyleBackColor = false; try { var useVisualStyleBackColorProperty = ReflectionHelper.GetProperty(control, "UseVisualStyleBackColor"); if (useVisualStyleBackColorProperty != null) { resetUseVisualStyleBackColor = (bool)useVisualStyleBackColorProperty; } } catch (InvalidCastException) { } catch (MissingMethodException) { } if (info.UsePaletteColors) { if (!info.ForeColor.Equals(default(TPaletteColors))) { control.ForeColor = GetColor(info.ForeColor); } if (!info.BackColor.Equals(default(TPaletteColors))) { control.BackColor = GetColor(info.BackColor); } var linkLabel = control as LinkLabel; if (linkLabel != null) { if (!info.LinkColor.Equals(default(TPaletteColors))) { linkLabel.LinkColor = GetColor(info.LinkColor); } if (!info.ActiveLinkColor.Equals(default(TPaletteColors))) { linkLabel.ActiveLinkColor = GetColor(info.ActiveLinkColor); } if (!info.DisabledLinkColor.Equals(default(TPaletteColors))) { linkLabel.DisabledLinkColor = GetColor(info.DisabledLinkColor); } if (!info.VisitedLinkColor.Equals(default(TPaletteColors))) { linkLabel.VisitedLinkColor = GetColor(info.VisitedLinkColor); } } else { var button = control as ButtonBase; if (button != null) { if (!info.FlatAppearanceBorderColor.Equals(default(TPaletteColors))) { button.FlatAppearance.BorderColor = GetColor(info.FlatAppearanceBorderColor); } if (!info.FlatAppearanceMouseDownBackColor.Equals(default(TPaletteColors))) { button.FlatAppearance.MouseDownBackColor = GetColor(info.FlatAppearanceMouseDownBackColor); } if (!info.FlatAppearanceMouseOverBackColor.Equals(default(TPaletteColors))) { button.FlatAppearance.MouseOverBackColor = GetColor(info.FlatAppearanceMouseOverBackColor); } } } } if (resetUseVisualStyleBackColor) { ReflectionHelper.SetProperty(control, "UseVisualStyleBackColor", true); } } else { var item = component as ToolStripItem; if (item != null) { if (info.UsePaletteColors) { if (!info.ForeColor.Equals(default(TPaletteColors))) { item.ForeColor = GetColor(info.ForeColor); } if (!info.BackColor.Equals(default(TPaletteColors))) { item.BackColor = GetColor(info.BackColor); } } } } }