From 159fbdd58dd8b935d4f342d1c51552f0eabc7518 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Thu, 29 Oct 2020 14:56:26 +0800 Subject: [PATCH] feat: ServerForm set the color of the control to red If the value is wrong --- Netch/Forms/ServerForm.cs | 47 +++++++++++++++++++++++--------------- Netch/Forms/SettingForm.cs | 18 +++------------ Netch/Utils/Utils.cs | 11 +++++++++ 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/Netch/Forms/ServerForm.cs b/Netch/Forms/ServerForm.cs index e9e458f0..0fa259bf 100644 --- a/Netch/Forms/ServerForm.cs +++ b/Netch/Forms/ServerForm.cs @@ -168,28 +168,37 @@ namespace Netch.Forms private void ControlButton_Click(object sender, EventArgs e) { - if (_checkActions.All(pair => pair.Value.Invoke(pair.Key.Text))) + Utils.Utils.ComponentIterator(this, component => Utils.Utils.ChangeControlForeColor(component, Color.Black)); + + var flag = true; + foreach (var pair in _checkActions.Where(pair => !pair.Value.Invoke(pair.Key.Text))) { - foreach (var pair in _saveActions) - { - switch (pair.Key) - { - case CheckBox c: - pair.Value.Invoke(c.Checked); - break; - default: - pair.Value.Invoke(pair.Key.Text); - break; - } - } - - if (Global.Settings.Server.IndexOf(Server) == -1) - Global.Settings.Server.Add(Server); - - MessageBoxX.Show(i18N.Translate("Saved")); + Utils.Utils.ChangeControlForeColor(pair.Key, Color.Red); + flag = false; } - else + + if (!flag) + { return; + } + + foreach (var pair in _saveActions) + { + switch (pair.Key) + { + case CheckBox c: + pair.Value.Invoke(c.Checked); + break; + default: + pair.Value.Invoke(pair.Key.Text); + break; + } + } + + if (Global.Settings.Server.IndexOf(Server) == -1) + Global.Settings.Server.Add(Server); + + MessageBoxX.Show(i18N.Translate("Saved")); Close(); } diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 4386fa71..9c44e0a5 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -282,26 +282,14 @@ namespace Netch.Forms private void ControlButton_Click(object sender, EventArgs e) { - void ChangeControlForeColor(Component component, Color color) - { - switch (component) - { - case TextBox _: - case ComboBox _: - if (((Control) component).ForeColor != color) - ((Control) component).ForeColor = color; - break; - } - } - - Utils.Utils.ComponentIterator(this, component => ChangeControlForeColor(component, Color.Black)); + Utils.Utils.ComponentIterator(this, component => Utils.Utils.ChangeControlForeColor(component, Color.Black)); #region Check var flag = true; foreach (var pair in _checkActions.Where(pair => !pair.Value.Invoke(pair.Key.Text))) { - ChangeControlForeColor(pair.Key, Color.Red); + Utils.Utils.ChangeControlForeColor(pair.Key, Color.Red); flag = false; } @@ -335,7 +323,7 @@ namespace Netch.Forms if (!stunFlag) { - ChangeControlForeColor(STUN_ServerComboBox, Color.Red); + Utils.Utils.ChangeControlForeColor(STUN_ServerComboBox, Color.Red); return; } diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index 1ea8c64c..386816aa 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -285,5 +285,16 @@ namespace Netch.Utils folder.DeleteTask("Netch Startup", 0); } } + + public static void ChangeControlForeColor(Component component, Color color) + { + switch (component) + { + case TextBox _: + case ComboBox _: + if (((Control) component).ForeColor != color) ((Control) component).ForeColor = color; + break; + } + } } } \ No newline at end of file