private static void FixMonoColors(ToolStripItem item, MonoTheme theme) { item.ForeColor = item.Enabled ? theme.ToolStripItemForeColor : theme.ToolStripItemDisabledForeColor; item.BackColor = theme.ToolStripItemBgColor; item.Font = new Font("Microsoft Sans Serif", 8.25f); item.EnabledChanged += (object sender, EventArgs e) => { ((ToolStripItem)sender).ForeColor = ((ToolStripItem)sender).Enabled ? theme.ToolStripItemForeColor : theme.ToolStripItemDisabledForeColor; }; if (item is ToolStripDropDownItem) { ToolStripDropDownItem ddItem = item as ToolStripDropDownItem; ddItem.DropDownOpening += MonoToolStripHelper.DropdownOpening; ddItem.DropDownClosed += MonoToolStripHelper.DropdownClosed; ddItem.DropDownOpening += (s, e) => { ddItem.DropDown.BackColor = theme.ToolStripItemBgColor; foreach (ToolStripItem subItem in ddItem.DropDownItems) { FixMonoColors(subItem, theme); } }; foreach (ToolStripItem subItem in ddItem.DropDownItems) { FixMonoColors(subItem, theme); } } }
public static void InitTheme(Color backColor) { if (backColor.R < 128 && backColor.G < 128 && backColor.B < 128) { Theme = new DarkMonoTheme(); } else { Theme = new MonoTheme(); } }
private static void FixMonoColors(Control container, MonoTheme theme) { if (ThemeHelper.IsExcludedFromTheme(container)) { return; } if (container is TextBox) { TextBox txt = (TextBox)container; txt.BorderStyle = BorderStyle.FixedSingle; txt.BackColor = txt.ReadOnly ? theme.TextBoxDisabledBgColor : theme.TextBoxEnabledBgColor; txt.ForeColor = theme.TextBoxForeColor; txt.ReadOnlyChanged += (object sender, EventArgs e) => { ((TextBox)sender).BackColor = ((TextBox)sender).ReadOnly ? theme.TextBoxDisabledBgColor : theme.TextBoxEnabledBgColor; }; } else if (container is Label) { Label lbl = (Label)container; if (lbl.BackColor == Color.White) { //Trackbar labels lbl.BackColor = theme.TextBoxEnabledBgColor; lbl.ForeColor = theme.TextBoxForeColor; } else { if (lbl.ForeColor == SystemColors.GrayText) { //Headers lbl.ForeColor = theme.GrayTextColor; } else if (lbl.ForeColor == SystemColors.ControlDark) { //ctrlRiskyOption lbl.ForeColor = theme.DarkTextColor; } else { //Regular label lbl.ForeColor = lbl.Enabled ? theme.LabelForeColor : theme.LabelDisabledForeColor; lbl.EnabledChanged += (object sender, EventArgs e) => { ((Label)sender).ForeColor = ((Label)sender).Enabled ? theme.LabelForeColor : theme.LabelDisabledForeColor; }; } } } else if (container is CheckBox) { CheckBox chk = (CheckBox)container; chk.FlatStyle = FlatStyle.Flat; chk.ForeColor = chk.Enabled ? theme.LabelForeColor : theme.LabelDisabledForeColor; if (chk.BackColor == SystemColors.ControlLightLight) { //Enable equalizer checkbox chk.BackColor = theme.TabBgColor; } chk.EnabledChanged += (object sender, EventArgs e) => { ((CheckBox)sender).ForeColor = ((CheckBox)sender).Enabled ? theme.LabelForeColor : theme.LabelDisabledForeColor; }; } else if (container is RadioButton) { ((RadioButton)container).ForeColor = ((RadioButton)container).Enabled ? theme.LabelForeColor : theme.LabelDisabledForeColor; ((RadioButton)container).EnabledChanged += (object sender, EventArgs e) => { ((RadioButton)sender).ForeColor = ((RadioButton)sender).Enabled ? theme.LabelForeColor : theme.LabelDisabledForeColor; }; } else if (container is TrackBar) { ((TrackBar)container).BackColor = theme.TabBgColor; } else if (container is Button) { Button btn = (Button)container; btn.FlatStyle = FlatStyle.Flat; btn.BackColor = btn.Enabled ? theme.ButtonEnabledBgColor : theme.ButtonDisabledBgColor; btn.ForeColor = theme.ButtonForeColor; btn.EnabledChanged += (object sender, EventArgs e) => { ((Button)sender).BackColor = ((Button)sender).Enabled ? theme.ButtonEnabledBgColor : theme.ButtonDisabledBgColor; }; } else if (container is ComboBox) { ComboBox cbo = (ComboBox)container; cbo.FlatStyle = FlatStyle.Flat; cbo.BackColor = cbo.Enabled ? theme.ComboEnabledBgColor : theme.ComboDisabledBgColor; cbo.ForeColor = theme.TextBoxForeColor; cbo.EnabledChanged += (object sender, EventArgs e) => { ((ComboBox)sender).BackColor = ((ComboBox)sender).Enabled ? theme.ComboEnabledBgColor : theme.ComboDisabledBgColor; }; } else if (container is GroupBox) { ((GroupBox)container).ForeColor = theme.LabelForeColor; } else if (container is TabControl) { ((TabControl)container).BackColor = theme.TabBgColor; } else if (container is TabPage) { ((TabPage)container).BackColor = theme.TabBgColor; } else if (container is Panel && !(container is TableLayoutPanel) && !(container is FlowLayoutPanel)) { ((Panel)container).BackColor = theme.PanelBgColor; } else if (container is DataGridView) { DataGridView dgv = (DataGridView)container; dgv.BackgroundColor = theme.ListBgColor; dgv.ForeColor = theme.LabelForeColor; dgv.GridColor = theme.LabelForeColor; dgv.DefaultCellStyle.ForeColor = theme.LabelForeColor; dgv.DefaultCellStyle.BackColor = theme.ListBgColor; dgv.ColumnHeadersDefaultCellStyle.ForeColor = theme.LabelForeColor; dgv.ColumnHeadersDefaultCellStyle.BackColor = theme.TabBgColor; } else if (container is DataGridTextBox) { ((DataGridTextBox)container).BackColor = theme.TextBoxEnabledBgColor; ((DataGridTextBox)container).ForeColor = theme.TextBoxForeColor; } else if (container is ListView) { ((ListView)container).BackColor = theme.ListBgColor; ((ListView)container).ForeColor = theme.LabelForeColor; } else if (container is ToolStrip) { ((ToolStrip)container).BackColor = theme.FormBgColor; if (container is ContextMenuStrip) { ((ContextMenuStrip)container).Opening += MonoToolStripHelper.ContextMenuOpening; ((ContextMenuStrip)container).Closed += MonoToolStripHelper.ContextMenuClosed; } else { ((ToolStrip)container).RenderMode = ToolStripRenderMode.System; } foreach (ToolStripItem item in ((ToolStrip)container).Items) { FixMonoColors(item, theme); } } if (container.ContextMenuStrip != null) { container.ContextMenuStrip.Opening += MonoToolStripHelper.ContextMenuOpening; container.ContextMenuStrip.Closed += MonoToolStripHelper.ContextMenuClosed; foreach (ToolStripItem item in container.ContextMenuStrip.Items) { FixMonoColors(item, theme); } } foreach (Control ctrl in container.Controls) { FixMonoColors(ctrl, theme); } }