private void ApplyStylesRecursive(Control control, ControlStyleOptions options) { if (!options.HasFlag(ControlStyleOptions.RulesRequired) || HasStyles(control)) { OnApplyStyles(control); } else { OnClearStyles(control); } if (options.HasFlag(ControlStyleOptions.Recursive) && control.HasChildren) { foreach (Control childControl in GetStylableChildControls(control)) { ApplyStylesRecursive(childControl, options); } if (control.ContextMenuStrip != null) { ApplyStylesRecursive(control.ContextMenuStrip, options); } } control.Invalidate(); }
public void ClearStyles(Control control, ControlStyleOptions options = ControlStyleOptions.Default) { OnClearStyles(control); RemoveControlInfo(control); if (options.HasFlag(ControlStyleOptions.Recursive) && control.HasChildren) { foreach (Control childControl in control.Controls) { ClearStyles(childControl, options); } } if (control.ContextMenuStrip != null) { ClearStyles(control.ContextMenuStrip, options); } control.Invalidate(); }
public void ApplyStyles(Control control, ControlStyleOptions options = ControlStyleOptions.Default) { MakeThisCurrentApplicator(); if (StyleSheet != null) { // Save control info for all controls before applying styles, which prevents changes to inherited properties affecting what is saved. // This is relevant for the BackColor and ForeColor properties of child controls. AddControlInfoRecursive(control, options); // Apply styles. ApplyStylesRecursive(control, options); } else { // Applying styles with a null style sheet is equivalent to clearing them. ClearStyles(control, options); } }
private void AddControlInfoRecursive(Control control, ControlStyleOptions options) { if (!options.HasFlag(ControlStyleOptions.RulesRequired) || HasStyles(control)) { AddControlInfo(control); } else { RemoveControlInfo(control); } if (options.HasFlag(ControlStyleOptions.Recursive) && control.HasChildren) { foreach (Control childControl in GetStylableChildControls(control)) { AddControlInfoRecursive(childControl, options); } if (control.ContextMenuStrip != null) { AddControlInfoRecursive(control.ContextMenuStrip, options); } } }