I want this same theme system but for a different form, adjust my theme code based on…
- User
I want this same theme system but for a different form, adjust my theme code based on the new forms components.
'new form components' private Panel panel1; private Panel panel2; private Label label1; private Panel panel3; private Label label5; private PictureBox pictureBox3; private Label label4; private PictureBox pictureBox2; private Label label2; private Label label3; private PictureBox pictureBox1; private MenuStrip menuStrip1; private ToolStripMenuItem fileToolStripMenuItem; private ToolStripMenuItem serverToolStripMenuItem; private ToolStripMenuItem fishSpeechToolStripMenuItem; private ToolStripMenuItem sTARTToolStripMenuItem; private ToolStripMenuItem whisperTurboToolStripMenuItem; private ToolStripMenuItem sTARTToolStripMenuItem1; private ToolStripMenuItem editToolStripMenuItem; private ToolStripMenuItem settingsToolStripMenuItem; private ToolStripMenuItem formSettingsToolStripMenuItem; private ToolStripMenuItem topmostToolStripMenuItem; private ToolStripMenuItem yESToolStripMenuItem; private ToolStripMenuItem nOToolStripMenuItem; private ToolStripMenuItem commSettingsToolStripMenuItem; private ToolStripMenuItem chatComboToolStripMenuItem; private ToolStripMenuItem oNToolStripMenuItem; private ToolStripMenuItem oFFToolStripMenuItem; private ToolStripMenuItem partyModeToolStripMenuItem; private ToolStripMenuItem oNToolStripMenuItem1; private ToolStripMenuItem oFFToolStripMenuItem1; private StatusStrip statusStrip1; private ToolStripStatusLabel toolStripStatusLabel1; private ListBox VoicesList; private Button F3B; private Button button2; private Panel panel4; private Label label6; private NAudio.Gui.VolumeSlider volumeSlider1; private TextBox textBox1; private Button button4; private Label label7; private TextBox textBox2; private Button button3; private Label label8; public ComboBox Previews; private Button ListenButton; private ToolTip toolTip1; private ToolStripMenuItem helpToolStripMenuItem; private ToolStripMenuItem pushToTalkToolStripMenuItem; private ToolStripMenuItem enableToolStripMenuItem; private ToolStripMenuItem disableToolStripMenuItem; private Panel panel5; private Button button7; private Label label10; private PictureBox pictureBox5; private Label label9; private Label label11; private Label label14; private Label label13; private Label label12; private TextBox RepBox; private TextBox TopPBox; private TextBox MaxTokenBox; private TextBox ChunkBox; private TextBox TempBox; private Button button6; private ToolStripMenuItem aboutToolStripMenuItem; private ToolStripStatusLabel toolStripStatusLabel2; private ToolStripMenuItem toolsToolStripMenuItem; private ToolStripMenuItem importToolStripMenuItem; private ToolStripMenuItem voiceToolStripMenuItem; private ToolStripMenuItem matchRecordToolStripMenuItem; private ToolStripMenuItem voiceToolStripMenuItem1; private ToolStripMenuItem recordToolStripMenuItem; private ToolStripMenuItem stopRecordToolStripMenuItem; private Button Key_1_NUM; private Panel panel6; private Button F2B; private Button Key_16_ZERO; private Button Key_15; private Button Key_8_PLUS; private Button Key_14_THREE; private Button Key_13_TWO; private Button Key_12_ONE; private Button Key_11_SIX; private Button Key_FIVE; private Button Key_9_FOUR; private Button Key_7_NINE; private Button Key_6_EIGHT; private Button Key_5_SEVEN; private Button Key_4_MIN; private Button Key_3_MULTI; private Button Key_2_SLASH; private Label label20; private PictureBox pictureBox4; private Button button5; private ContextMenuStrip contextMenuStrip1; private ToolStripMenuItem loadFromFileToolStripMenuItem; private FolderBrowserDialog folderBrowserDialog1; private Button F3BB; private Button F8B; private Button F7B; private Button F6B; private Button F5B; private Button F4B; private Button F12B; private Button F11B; private Button F10B; private Button F9B; private Button F1B; private ToolStripMenuItem keypadderToolStripMenuItem; private ToolStripMenuItem confirmModeToolStripMenuItem; private Button button1; private ToolStripMenuItem tTSBaseToolStripMenuItem; private ToolStripMenuItem fishSpeechToolStripMenuItem1; private ToolStripMenuItem zonosToolStripMenuItem; private ToolStripMenuItem viewToolStripMenuItem; private Panel panel7; private Label label21; private PictureBox pictureBox6; private TextBox HappyBox; private Label label15; private TextBox AngryBox; private Label label22; private TextBox ShockedBox; private Label label19; private TextBox ScaredBox; private Label label18; private TextBox GrossBox; private Label label17; private TextBox SadBox; private Label label16; private TextBox NeutralBox; private Label label23; private TextBox OtherBox; private Label label24; private Button button13; private Button button12; private Button button8; private Panel panel8; private Button button10; private Button button11; private Label label33; private PictureBox pictureBox7; private TextBox SpeechSpeedBox; private Label label25; private Panel panel9; private ComboBox comboBox1; private Label label26; private Label label27; private PictureBox pictureBox8; private Label label28; private PictureBox OffMap; private Button HP; private Button SP; private Button SN; private Button HN; private Button SHN; private Button SHP; private Button GN; private Button GP; private Button NN; private Button NP; private Button AN; private Button AP; private Button SCN; private Button SCP; private Button ON; private Button OP; private Button button9; private Label MyLink; private Button CFGN; private Button CFGP; private TextBox CFGBox; private Label label29; private Button SPSN; private Button SPSP; private Button button16; private Button button17; private CheckBox EnabPrefix; private Button SpeakerAP; private Button Bum; private CheckBox AutoEmote; private Button button14; private TextBox SearchBox; private CheckBox checkBox3; private ToolStripProgressBar toolStripProgressBar1; private System.Windows.Forms.Timer opacityTimer; private ToolStripMenuItem outputsToolStripMenuItem; private ToolStripMenuItem cacheOutputsToolStripMenuItem; private ToolStripMenuItem setDirectorytToolStripMenuItem; private FolderBrowserDialog folderBrowserDialog2; private ToolStripMenuItem tTSToolStripMenuItem; private ToolStripMenuItem fishSpeechToolStripMenuItem2; private ToolStripMenuItem zonosToolStripMenuItem1; private ToolStripMenuItem constructiveChunksToolStripMenuItem; private ToolStripMenuItem constructiveTokensToolStripMenuItem; private Panel panel10; private Label label32; private PictureBox pictureBox9; private Label label30; private ComboBox comboBoxModels; private Label label31; private ComboBox TranslationMdl; private Label label34; private ComboBox comboBox4; private Label label35; private ComboBox SpellCheckMdl; private ToolStripMenuItem ollamaToolStripMenuItem; private ToolStripMenuItem longGenerationsModeToolStripMenuItem; private ToolStripMenuItem translationModeToolStripMenuItem; private ToolStripMenuItem spellCheckModeToolStripMenuItem; private ToolStripMenuItem debugToolStripMenuItem; private ToolStripMenuItem sTTToolStripMenuItem; private ToolStripMenuItem oNToolStripMenuItem2; private ToolStripMenuItem oFFToolStripMenuItem2; private ToolStripMenuItem portableChatboxToolStripMenuItem; public TextBox textBox3; private ToolStripMenuItem oNToolStripMenuItem3; private ToolStripMenuItem oFFToolStripMenuItem3; private Panel indexpnl; private Label label41; private PictureBox pictureBox10; private Label label36; private ComboBox comboBox2; private ToolStripMenuItem indexTTSToolStripMenuItem; private ToolStripMenuItem sTARTToolStripMenuItem2; private ToolStripMenuItem recentPlayersToolStripMenuItem; private ToolStripMenuItem incrementalSeedingToolStripMenuItem; private ToolStripMenuItem stateToolStripMenuItem; private ToolStripMenuItem oFFToolStripMenuItem4; private ToolStripMenuItem previewModeToolStripMenuItem; private ToolStripMenuItem oNToolStripMenuItem4; private ToolStripMenuItem oFFToolStripMenuItem5; public ComboBox comboBoxOutputDevices; public ComboBox comboBoxInputDevices; public Button LookButton; private ToolStripMenuItem finetuneModelToolStripMenuItem; private ToolStripMenuItem fishSpeechToolStripMenuItem3; private ToolStripMenuItem toolStripMenuItem3; private ToolStripMenuItem makeToolStripMenuItem; private ToolStripMenuItem startTrainToolStripMenuItem;
'my code' private Color DarkenColor(Color color, float percent) { percent = Math.Clamp(percent, 0f, 1f); int r = (int)(color.R * (1 - percent)); int g = (int)(color.G * (1 - percent)); int b = (int)(color.B * (1 - percent)); return Color.FromArgb(color.A, r, g, b); }
private Random _rand = new Random();
private Color _lastMainStart; private Color _lastMainEnd; private Color _lastAccentsStart; private Color _lastAccentsEnd; private Color _lastTextColor;
private Color RandomColor(int min = 0, int max = 255) { return Color.FromArgb( 255, _rand.Next(min, max + 1), _rand.Next(min, max + 1), _rand.Next(min, max + 1)); }
private void GenerateRandomTheme(bool reapply = false) { if (!reapply || _lastMainStart == Color.Empty) { _lastMainStart = RandomColor(10, 60); _lastMainEnd = RandomColor(30, 100); _lastAccentsStart = RandomColor(150, 255); _lastAccentsEnd = RandomColor(100, 200); _lastTextColor = RandomColor(200, 255); }
Theme(_lastMainStart, _lastMainEnd, _lastAccentsStart, _lastAccentsEnd, _lastTextColor);}
private void Theme(Color mainStart, Color mainEnd, Color accentsStart, Color accentsEnd, Color textcolor) { void SetGradient(Control control, Color startColor, Color endColor) { Bitmap bmp = new Bitmap(control.Width, control.Height); using (Graphics g = Graphics.FromImage(bmp)) { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, bmp.Width, bmp.Height), startColor, endColor, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { g.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height); } } control.BackgroundImage = bmp; control.BackgroundImageLayout = ImageLayout.Stretch; }
Color GetContrastingTextColor(Color background, Color fallback) { // Calculate luminance per ITU-R BT.709 double luminance = (0.2126 * background.R + 0.7152 * background.G + 0.0722 * background.B) / 255; // If background is light, return black or dark gray else fallback color if (luminance > 0.7) return Color.FromArgb(255, 30, 30, 30); // a dark gray for better contrast instead of pure black else return fallback; } // Labels label1.BackColor = Color.Transparent; label2.BackColor = Color.Transparent; label3.BackColor = Color.Transparent; label4.BackColor = Color.Transparent; label1.ForeColor = textcolor; label2.ForeColor = textcolor; label3.ForeColor = textcolor; label4.ForeColor = textcolor; var buttons = new Button[] {Create_Base, Upload_Voices, Create_Speaker, Create_NPY, Pack_Protos, Transcribe_Labs, Post_Process, Preview_Voice, Rename_Dataset, Train_Button, OFFSCREEN, button1, button3, button4, button5 };
foreach (var btn in buttons) { SetGradient(btn, accentsStart, accentsEnd); // Pick foreground color contrasting against middle color of gradient (average color) Color midColor = Color.FromArgb( (accentsStart.R + accentsEnd.R) / 2, (accentsStart.G + accentsEnd.G) / 2, (accentsStart.B + accentsEnd.B) / 2); btn.ForeColor = GetContrastingTextColor(midColor, textcolor); } var darkButtons = new Button[] {Delete_Dataset, Delete_Voice_Files, button2 };
Color DarkenColor(Color color, float factor) { return Color.FromArgb( color.A, (int)(color.R * (1 - factor)), (int)(color.G * (1 - factor)), (int)(color.B * (1 - factor)) ); } foreach (var btn in darkButtons) { Color startDark = DarkenColor(accentsStart, 0.33f); Color endDark = DarkenColor(accentsEnd, 0.33f); SetGradient(btn, startDark, endDark); Color midColor = Color.FromArgb( (startDark.R + endDark.R) / 2, (startDark.G + endDark.G) / 2, (startDark.B + endDark.B) / 2); btn.ForeColor = GetContrastingTextColor(midColor, textcolor); } Dataset_Name.BackColor = mainStart; Dataset_Name.ForeColor = GetContrastingTextColor(mainStart, textcolor); Speaker_Name.BackColor = mainStart; Speaker_Name.ForeColor = GetContrastingTextColor(mainStart, textcolor); Dataset_List.BackColor = mainStart; Dataset_List.ForeColor = GetContrastingTextColor(mainStart, textcolor); Speaker_List.BackColor = mainStart; Speaker_List.ForeColor = GetContrastingTextColor(mainStart, textcolor); Voice_List.BackColor = mainStart; Voice_List.ForeColor = GetContrastingTextColor(mainStart, textcolor); menuStrip1.BackColor = accentsStart; menuStrip1.ForeColor = GetContrastingTextColor(accentsStart, textcolor); var menuItems = new ToolStripMenuItem[] {fileToolStripMenuItem, exitToolStripMenuItem, toolsToolStripMenuItem, vocalsToolStripMenuItem, uVR5ToolStripMenuItem, serverToolStripMenuItem, sTARTToolStripMenuItem, sTOPToolStripMenuItem, transcribeToolStripMenuItem, whisperToolStripMenuItem, startServerToolStripMenuItem, stopServerToolStripMenuItem, githubToolStripMenuItem, docsToolStripMenuItem, themeToolStripMenuItem, rollDiceToolStripMenuItem };
foreach (var item in menuItems) { item.BackColor = accentsStart; item.ForeColor = GetContrastingTextColor(accentsStart, textcolor); } Bitmap formBmp = new Bitmap(this.Width, this.Height); using (Graphics g = Graphics.FromImage(formBmp)) { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, formBmp.Width, formBmp.Height), mainStart, accentsStart, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { g.FillRectangle(brush, 0, 0, formBmp.Width, formBmp.Height); } } this.BackgroundImage = formBmp; this.BackgroundImageLayout = ImageLayout.Stretch;}
'final thoughts' please send back entire code no commentary just provide back in nice copiable pieces for each void or whatever.
- Assistant
private Color DarkenColor(Color color, float percent) { percent = Math.Clamp(percent, 0f, 1f); int r = (int)(color.R * (1 - percent)); int g = (int)(color.G * (1 - percent)); int b = (int)(color.B * (1 - percent)); return Color.FromArgb(color.A, r, g, b); } private Random _rand = new Random(); private Color _lastMainStart; private Color _lastMainEnd; private Color _lastAccentsStart; private Color _lastAccentsEnd; private Color _lastTextColor; private Color RandomColor(int min = 0, int max = 255) { return Color.FromArgb( 255, _rand.Next(min, max + 1), _rand.Next(min, max + 1), _rand.Next(min, max + 1)); } private void GenerateRandomTheme(bool reapply = false) { if (!reapply || _lastMainStart == Color.Empty) { _lastMainStart = RandomColor(10, 60); _lastMainEnd = RandomColor(30, 100); _lastAccentsStart = RandomColor(150, 255); _lastAccentsEnd = RandomColor(100, 200); _lastTextColor = RandomColor(200, 255); } Theme(_lastMainStart, _lastMainEnd, _lastAccentsStart, _lastAccentsEnd, _lastTextColor); } private void Theme(Color mainStart, Color mainEnd, Color accentsStart, Color accentsEnd, Color textcolor) { void SetGradient(Control control, Color startColor, Color endColor) { if (control == null || control.Width == 0 || control.Height == 0) return; Bitmap bmp = new Bitmap(control.Width, control.Height); using (Graphics g = Graphics.FromImage(bmp)) { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, bmp.Width, bmp.Height), startColor, endColor, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { g.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height); } } control.BackgroundImage = bmp; control.BackgroundImageLayout = ImageLayout.Stretch; } Color GetContrastingTextColor(Color background, Color fallback) { double luminance = (0.2126 * background.R + 0.7152 * background.G + 0.0722 * background.B) / 255; if (luminance > 0.7) return Color.FromArgb(255, 30, 30, 30); else return fallback; } // Labels transparent background & text color var labels = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13, label14, label15, label16, label17, label18, label19, label20, label21, label22, label23, label24, label25, label26, label27, label28, label29, label30, label31, label32, label33, label34, label35, label36, label41, MyLink }; foreach (var lbl in labels) { if (lbl != null) { lbl.BackColor = Color.Transparent; lbl.ForeColor = textcolor; } } // Panels gradient background var panelsGradient = new Panel[] { panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, panel10, indexpnl }; foreach (var pnl in panelsGradient) { if (pnl != null) { SetGradient(pnl, mainStart, mainEnd); } } // PictureBoxes transparent background if possible var pictures = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10, OffMap }; foreach (var pb in pictures) { if (pb != null) { pb.BackColor = Color.Transparent; } } // MenuStrip and ToolStripMenuItems if (menuStrip1 != null) { menuStrip1.BackColor = accentsStart; menuStrip1.ForeColor = GetContrastingTextColor(accentsStart, textcolor); } var menuItems = new ToolStripMenuItem[] { fileToolStripMenuItem, serverToolStripMenuItem, fishSpeechToolStripMenuItem, sTARTToolStripMenuItem, whisperTurboToolStripMenuItem, sTARTToolStripMenuItem1, editToolStripMenuItem, settingsToolStripMenuItem, formSettingsToolStripMenuItem, topmostToolStripMenuItem, yESToolStripMenuItem, nOToolStripMenuItem, commSettingsToolStripMenuItem, chatComboToolStripMenuItem, oNToolStripMenuItem, oFFToolStripMenuItem, partyModeToolStripMenuItem, oNToolStripMenuItem1, oFFToolStripMenuItem1, helpToolStripMenuItem, pushToTalkToolStripMenuItem, enableToolStripMenuItem, disableToolStripMenuItem, aboutToolStripMenuItem, toolsToolStripMenuItem, importToolStripMenuItem, voiceToolStripMenuItem, matchRecordToolStripMenuItem, voiceToolStripMenuItem1, recordToolStripMenuItem, stopRecordToolStripMenuItem, keypadderToolStripMenuItem, confirmModeToolStripMenuItem, tTSBaseToolStripMenuItem, fishSpeechToolStripMenuItem1, zonosToolStripMenuItem, viewToolStripMenuItem, tTSToolStripMenuItem, fishSpeechToolStripMenuItem2, zonosToolStripMenuItem1, constructiveChunksToolStripMenuItem, constructiveTokensToolStripMenuItem, ollamaToolStripMenuItem, longGenerationsModeToolStripMenuItem, translationModeToolStripMenuItem, spellCheckModeToolStripMenuItem, debugToolStripMenuItem, sTTToolStripMenuItem, oNToolStripMenuItem2, oFFToolStripMenuItem2, portableChatboxToolStripMenuItem, oNToolStripMenuItem3, oFFToolStripMenuItem3, indexTTSToolStripMenuItem, sTARTToolStripMenuItem2, recentPlayersToolStripMenuItem, incrementalSeedingToolStripMenuItem, stateToolStripMenuItem, oFFToolStripMenuItem4, previewModeToolStripMenuItem, oNToolStripMenuItem4, oFFToolStripMenuItem5, finetuneModelToolStripMenuItem, fishSpeechToolStripMenuItem3, toolStripMenuItem3, makeToolStripMenuItem, startTrainToolStripMenuItem, outputsToolStripMenuItem, cacheOutputsToolStripMenuItem, setDirectorytToolStripMenuItem, }; foreach (var item in menuItems) { if (item != null) { item.BackColor = accentsStart; item.ForeColor = GetContrastingTextColor(accentsStart, textcolor); } } // StatusStrip and labels if (statusStrip1 != null) { statusStrip1.BackColor = accentsEnd; statusStrip1.ForeColor = GetContrastingTextColor(accentsEnd, textcolor); } if (toolStripStatusLabel1 != null) { toolStripStatusLabel1.ForeColor = textcolor; } if (toolStripStatusLabel2 != null) { toolStripStatusLabel2.ForeColor = textcolor; } if (toolStripProgressBar1 != null) { toolStripProgressBar1.BackColor = accentsStart; toolStripProgressBar1.ForeColor = textcolor; } // ListBox VoicesList if (VoicesList != null) { VoicesList.BackColor = mainStart; VoicesList.ForeColor = GetContrastingTextColor(mainStart, textcolor); } // TextBoxes var textBoxes = new TextBox[] { textBox1, textBox2, textBox3, RepBox, TopPBox, MaxTokenBox, ChunkBox, TempBox, HappyBox, AngryBox, ShockedBox, ScaredBox, GrossBox, SadBox, NeutralBox, OtherBox, SpeechSpeedBox, CFGBox, SearchBox }; foreach (var tb in textBoxes) { if (tb != null) { tb.BackColor = mainEnd; tb.ForeColor = GetContrastingTextColor(mainEnd, textcolor); tb.BorderStyle = BorderStyle.FixedSingle; } } // ComboBoxes var combos = new ComboBox[] { Previews, comboBox1, comboBox2, comboBox4, comboBoxModels, TranslationMdl, SpellCheckMdl, comboBoxOutputDevices, comboBoxInputDevices }; foreach (var cb in combos) { if (cb != null) { cb.BackColor = mainEnd; cb.ForeColor = GetContrastingTextColor(mainEnd, textcolor); } } // ToolTip ForeColor or BackColor adjustment if desired (optional) // No direct ForeColor changes for ToolTip // Buttons - main accent gradient var buttons = new Button[] { F3B, button2, button4, button3, ListenButton, button7, button6, Key_1_NUM, F2B, Key_16_ZERO, Key_15, Key_8_PLUS, Key_14_THREE, Key_13_TWO, Key_12_ONE, Key_11_SIX, Key_FIVE, Key_9_FOUR, Key_7_NINE, Key_6_EIGHT, Key_5_SEVEN, Key_4_MIN, Key_3_MULTI, Key_2_SLASH, button5, F3BB, F8B, F7B, F6B, F5B, F4B, F12B, F11B, F10B, F9B, F1B, button1, button13, button12, button8, button10, button11, HP, SP, SN, HN, SHN, SHP, GN, GP, NN, NP, AN, AP, SCN, SCP, ON, OP, button9, CFGN, CFGP, SPSN, SPSP, button16, button17, SpeakerAP, Bum, button14, LookButton }; foreach (var btn in buttons) { if (btn == null) continue; SetGradient(btn, accentsStart, accentsEnd); Color midColor = Color.FromArgb( (accentsStart.R + accentsEnd.R) / 2, (accentsStart.G + accentsEnd.G) / 2, (accentsStart.B + accentsEnd.B) / 2); btn.ForeColor = GetContrastingTextColor(midColor, textcolor); btn.FlatAppearance.BorderColor = DarkenColor(midColor, 0.3f); } // Darker buttons gradient (if any specific to dark style) var darkButtons = new Button[] { // None specifically identified in new form, you can add if any should be darker }; foreach (var btn in darkButtons) { if (btn == null) continue; Color startDark = DarkenColor(accentsStart, 0.33f); Color endDark = DarkenColor(accentsEnd, 0.33f); SetGradient(btn, startDark, endDark); Color midColor = Color.FromArgb( (startDark.R + endDark.R) / 2, (startDark.G + endDark.G) / 2, (startDark.B + endDark.B) / 2); btn.ForeColor = GetContrastingTextColor(midColor, textcolor); btn.FlatAppearance.BorderColor = DarkenColor(midColor, 0.3f); } // CheckBoxes ForeColor var checkBoxes = new CheckBox[] { EnabPrefix, AutoEmote, checkBox3 }; foreach (var cb in checkBoxes) { if (cb != null) { cb.ForeColor = textcolor; cb.BackColor = Color.Transparent; } } // Set form background gradient Bitmap formBmp = new Bitmap(this.Width, this.Height); using (Graphics g = Graphics.FromImage(formBmp)) { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, formBmp.Width, formBmp.Height), mainStart, accentsStart, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { g.FillRectangle(brush, 0, 0, formBmp.Width, formBmp.Height); } } this.BackgroundImage = formBmp; this.BackgroundImageLayout = ImageLayout.Stretch; } - User
clear all backgrounds and images first, return entire code with this in mind ty.
- Assistant
private Color DarkenColor(Color color, float percent) { percent = Math.Clamp(percent, 0f, 1f); int r = (int)(color.R * (1 - percent)); int g = (int)(color.G * (1 - percent)); int b = (int)(color.B * (1 - percent)); return Color.FromArgb(color.A, r, g, b); } private Random _rand = new Random(); private Color _lastMainStart; private Color _lastMainEnd; private Color _lastAccentsStart; private Color _lastAccentsEnd; private Color _lastTextColor; private Color RandomColor(int min = 0, int max = 255) { return Color.FromArgb( 255, _rand.Next(min, max + 1), _rand.Next(min, max + 1), _rand.Next(min, max + 1)); } private void GenerateRandomTheme(bool reapply = false) { if (!reapply || _lastMainStart == Color.Empty) { _lastMainStart = RandomColor(10, 60); _lastMainEnd = RandomColor(30, 100); _lastAccentsStart = RandomColor(150, 255); _lastAccentsEnd = RandomColor(100, 200); _lastTextColor = RandomColor(200, 255); } Theme(_lastMainStart, _lastMainEnd, _lastAccentsStart, _lastAccentsEnd, _lastTextColor); } private void Theme(Color mainStart, Color mainEnd, Color accentsStart, Color accentsEnd, Color textcolor) { void SetGradient(Control control, Color startColor, Color endColor) { if (control == null || control.Width == 0 || control.Height == 0) return; Bitmap bmp = new Bitmap(control.Width, control.Height); using (Graphics g = Graphics.FromImage(bmp)) { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, bmp.Width, bmp.Height), startColor, endColor, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { g.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height); } } control.BackgroundImage = bmp; control.BackgroundImageLayout = ImageLayout.Stretch; } Color GetContrastingTextColor(Color background, Color fallback) { double luminance = (0.2126 * background.R + 0.7152 * background.G + 0.0722 * background.B) / 255; if (luminance > 0.7) return Color.FromArgb(255, 30, 30, 30); else return fallback; } // Clear all backgrounds and images first // Clear Panels var allPanels = new Panel[] { panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, panel10, indexpnl }; foreach (var pnl in allPanels) { if (pnl != null) { pnl.BackgroundImage = null; pnl.BackColor = Color.Transparent; } } // Clear Labels background and images var labels = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13, label14, label15, label16, label17, label18, label19, label20, label21, label22, label23, label24, label25, label26, label27, label28, label29, label30, label31, label32, label33, label34, label35, label36, label41, MyLink }; foreach (var lbl in labels) { if (lbl != null) { lbl.BackgroundImage = null; lbl.BackColor = Color.Transparent; } } // Clear PictureBoxes images and backgrounds var pictures = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10, OffMap }; foreach (var pb in pictures) { if (pb != null) { pb.Image = null; pb.BackgroundImage = null; pb.BackColor = Color.Transparent; } } // Clear MenuStrip background and images if (menuStrip1 != null) { menuStrip1.BackgroundImage = null; menuStrip1.BackColor = Color.Transparent; } // Clear ToolStripMenuItems background and images var menuItems = new ToolStripMenuItem[] { fileToolStripMenuItem, serverToolStripMenuItem, fishSpeechToolStripMenuItem, sTARTToolStripMenuItem, whisperTurboToolStripMenuItem, sTARTToolStripMenuItem1, editToolStripMenuItem, settingsToolStripMenuItem, formSettingsToolStripMenuItem, topmostToolStripMenuItem, yESToolStripMenuItem, nOToolStripMenuItem, commSettingsToolStripMenuItem, chatComboToolStripMenuItem, oNToolStripMenuItem, oFFToolStripMenuItem, partyModeToolStripMenuItem, oNToolStripMenuItem1, oFFToolStripMenuItem1, helpToolStripMenuItem, pushToTalkToolStripMenuItem, enableToolStripMenuItem, disableToolStripMenuItem, aboutToolStripMenuItem, toolsToolStripMenuItem, importToolStripMenuItem, voiceToolStripMenuItem, matchRecordToolStripMenuItem, voiceToolStripMenuItem1, recordToolStripMenuItem, stopRecordToolStripMenuItem, keypadderToolStripMenuItem, confirmModeToolStripMenuItem, tTSBaseToolStripMenuItem, fishSpeechToolStripMenuItem1, zonosToolStripMenuItem, viewToolStripMenuItem, tTSToolStripMenuItem, fishSpeechToolStripMenuItem2, zonosToolStripMenuItem1, constructiveChunksToolStripMenuItem, constructiveTokensToolStripMenuItem, ollamaToolStripMenuItem, longGenerationsModeToolStripMenuItem, translationModeToolStripMenuItem, spellCheckModeToolStripMenuItem, debugToolStripMenuItem, sTTToolStripMenuItem, oNToolStripMenuItem2, oFFToolStripMenuItem2, portableChatboxToolStripMenuItem, oNToolStripMenuItem3, oFFToolStripMenuItem3, indexTTSToolStripMenuItem, sTARTToolStripMenuItem2, recentPlayersToolStripMenuItem, incrementalSeedingToolStripMenuItem, stateToolStripMenuItem, oFFToolStripMenuItem4, previewModeToolStripMenuItem, oNToolStripMenuItem4, oFFToolStripMenuItem5, finetuneModelToolStripMenuItem, fishSpeechToolStripMenuItem3, toolStripMenuItem3, makeToolStripMenuItem, startTrainToolStripMenuItem, outputsToolStripMenuItem, cacheOutputsToolStripMenuItem, setDirectorytToolStripMenuItem, }; foreach (var item in menuItems) { if (item != null) { item.BackgroundImage = null; item.BackColor = Color.Transparent; } } // Clear StatusStrip and its labels background & images if (statusStrip1 != null) { statusStrip1.BackgroundImage = null; statusStrip1.BackColor = Color.Transparent; } if (toolStripStatusLabel1 != null) toolStripStatusLabel1.BackgroundImage = null; if (toolStripStatusLabel2 != null) toolStripStatusLabel2.BackgroundImage = null; if (toolStripProgressBar1 != null) toolStripProgressBar1.BackgroundImage = null; // Clear ListBox background & images if (VoicesList != null) { VoicesList.BackgroundImage = null; VoicesList.BackColor = Color.Transparent; } // Clear TextBox backgrounds & images var textBoxes = new TextBox[] { textBox1, textBox2, textBox3, RepBox, TopPBox, MaxTokenBox, ChunkBox, TempBox, HappyBox, AngryBox, ShockedBox, ScaredBox, GrossBox, SadBox, NeutralBox, OtherBox, SpeechSpeedBox, CFGBox, SearchBox }; foreach (var tb in textBoxes) { if (tb != null) { tb.BackgroundImage = null; tb.BackColor = Color.White; // TextBoxes typically have white bg by default, will override later } } // Clear ComboBox background & images var combos = new ComboBox[] { Previews, comboBox1, comboBox2, comboBox4, comboBoxModels, TranslationMdl, SpellCheckMdl, comboBoxOutputDevices, comboBoxInputDevices }; foreach (var cb in combos) { if (cb != null) { cb.BackgroundImage = null; cb.BackColor = Color.White; // Default white, will override below } } // Clear Buttons background & images var buttons = new Button[] { F3B, button2, button4, button3, ListenButton, button7, button6, Key_1_NUM, F2B, Key_16_ZERO, Key_15, Key_8_PLUS, Key_14_THREE, Key_13_TWO, Key_12_ONE, Key_11_SIX, Key_FIVE, Key_9_FOUR, Key_7_NINE, Key_6_EIGHT, Key_5_SEVEN, Key_4_MIN, Key_3_MULTI, Key_2_SLASH, button5, F3BB, F8B, F7B, F6B, F5B, F4B, F12B, F11B, F10B, F9B, F1B, button1, button13, button12, button8, button10, button11, HP, SP, SN, HN, SHN, SHP, GN, GP, NN, NP, AN, AP, SCN, SCP, ON, OP, button9, CFGN, CFGP, SPSN, SPSP, button16, button17, SpeakerAP, Bum, button14, LookButton }; foreach (var btn in buttons) { if (btn != null) { btn.BackgroundImage = null; btn.Image = null; btn.FlatAppearance.BorderColor = Color.Empty; btn.FlatAppearance.BorderSize = 0; btn.BackColor = Color.Transparent; } } // Clear CheckBoxes background & images var checkBoxes = new CheckBox[] { EnabPrefix, AutoEmote, checkBox3 }; foreach (var cb in checkBoxes) { if (cb != null) { cb.BackgroundImage = null; cb.BackColor = Color.Transparent; } } // Now re-apply colors and gradients // Labels ForeColor foreach (var lbl in labels) { if (lbl != null) { lbl.ForeColor = textcolor; } } // Panels gradient background foreach (var pnl in allPanels) { if (pnl != null) { SetGradient(pnl, mainStart, mainEnd); } } // PictureBoxes BackColor transparent (without background/image) foreach (var pb in pictures) { if (pb != null) { pb.BackColor = Color.Transparent; } } // MenuStrip and ToolStripMenuItems coloring if (menuStrip1 != null) { menuStrip1.BackColor = accentsStart; menuStrip1.ForeColor = GetContrastingTextColor(accentsStart, textcolor); } foreach (var item in menuItems) { if (item != null) { item.BackColor = accentsStart; item.ForeColor = GetContrastingTextColor(accentsStart, textcolor); } } // StatusStrip and labels coloring if (statusStrip1 != null) { statusStrip1.BackColor = accentsEnd; statusStrip1.ForeColor = GetContrastingTextColor(accentsEnd, textcolor); } if (toolStripStatusLabel1 != null) { toolStripStatusLabel1.ForeColor = textcolor; } if (toolStripStatusLabel2 != null) { toolStripStatusLabel2.ForeColor = textcolor; } if (toolStripProgressBar1 != null) { toolStripProgressBar1.BackColor = accentsStart; toolStripProgressBar1.ForeColor = textcolor; } // ListBox VoicesList if (VoicesList != null) { VoicesList.BackColor = mainStart; VoicesList.ForeColor = GetContrastingTextColor(mainStart, textcolor); } // TextBoxes coloring foreach (var tb in textBoxes) { if (tb != null) { tb.BackColor = mainEnd; tb.ForeColor = GetContrastingTextColor(mainEnd, textcolor); tb.BorderStyle = BorderStyle.FixedSingle; } } // ComboBoxes coloring foreach (var cb in combos) { if (cb != null) { cb.BackColor = mainEnd; cb.ForeColor = GetContrastingTextColor(mainEnd, textcolor); } } // Buttons gradient background and colors foreach (var btn in buttons) { if (btn == null) continue; SetGradient(btn, accentsStart, accentsEnd); Color midColor = Color.FromArgb( (accentsStart.R + accentsEnd.R) / 2, (accentsStart.G + accentsEnd.G) / 2, (accentsStart.B + accentsEnd.B) / 2); btn.ForeColor = GetContrastingTextColor(midColor, textcolor); btn.FlatAppearance.BorderColor = DarkenColor(midColor, 0.3f); btn.FlatAppearance.BorderSize = 1; btn.FlatStyle = FlatStyle.Flat; } // CheckBoxes coloring foreach (var cb in checkBoxes) { if (cb != null) { cb.ForeColor = textcolor; cb.BackColor = Color.Transparent; } } // Set form background gradient Bitmap formBmp = new Bitmap(this.Width, this.Height); using (Graphics g = Graphics.FromImage(formBmp)) { using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, formBmp.Width, formBmp.Height), mainStart, accentsStart, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { g.FillRectangle(brush, 0, 0, formBmp.Width, formBmp.Height); } } this.BackgroundImage = formBmp; this.BackgroundImageLayout = ImageLayout.Stretch; }