From 8f1f8de9064aedc278eded0e8be084127a09e8df Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Tue, 7 Jul 2020 01:45:48 +0800
Subject: [PATCH] add MessageBoxX()
---
Netch/Controllers/HTTPController.cs | 2 +-
Netch/Forms/GlobalBypassIPForm.cs | 8 ++++----
Netch/Forms/MainForm.Control.cs | 10 ++++------
Netch/Forms/MainForm.MenuStrip.cs | 26 +++++++++++++-------------
Netch/Forms/MainForm.Misc.cs | 2 +-
Netch/Forms/MainForm.Profile.cs | 8 ++++----
Netch/Forms/MainForm.cs | 16 +++++++++-------
Netch/Forms/Mode/Process.cs | 18 +++++++++---------
Netch/Forms/Server/Shadowsocks.cs | 2 +-
Netch/Forms/Server/ShadowsocksR.cs | 2 +-
Netch/Forms/Server/Socks5.cs | 2 +-
Netch/Forms/Server/Trojan.cs | 2 +-
Netch/Forms/Server/Vmess.cs | 4 ++--
Netch/Forms/SettingForm.cs | 16 ++++++++--------
Netch/Forms/SubscribeForm.cs | 12 ++++++------
Netch/Netch.cs | 4 ++--
Netch/Utils/Configuration.cs | 6 +++---
Netch/Utils/MessageBoxX.cs | 24 ++++++++++++++++++++++++
18 files changed, 94 insertions(+), 70 deletions(-)
create mode 100644 Netch/Utils/MessageBoxX.cs
diff --git a/Netch/Controllers/HTTPController.cs b/Netch/Controllers/HTTPController.cs
index 004644c5..87716f36 100644
--- a/Netch/Controllers/HTTPController.cs
+++ b/Netch/Controllers/HTTPController.cs
@@ -49,7 +49,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- if (MessageBox.Show(i18N.Translate("Failed to set the system proxy, it may be caused by the lack of dependent programs. Do you want to jump to Netch's official website to download dependent programs?"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
+ if (MessageBoxX.Show(i18N.Translate("Failed to set the system proxy, it may be caused by the lack of dependent programs. Do you want to jump to Netch's official website to download dependent programs?"), confirm:true) == DialogResult.OK)
{
Process.Start("https://netch.org/#/?id=%e4%be%9d%e8%b5%96");
}
diff --git a/Netch/Forms/GlobalBypassIPForm.cs b/Netch/Forms/GlobalBypassIPForm.cs
index dc8e4a0b..2e83482d 100644
--- a/Netch/Forms/GlobalBypassIPForm.cs
+++ b/Netch/Forms/GlobalBypassIPForm.cs
@@ -43,12 +43,12 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please enter a correct IP address"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please enter a correct IP address"));
}
}
else
{
- MessageBox.Show(i18N.Translate("Please enter an IP"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please enter an IP"));
}
}
@@ -60,7 +60,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please select an IP"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select an IP"));
}
}
@@ -73,7 +73,7 @@ namespace Netch.Forms
}
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Close();
}
}
diff --git a/Netch/Forms/MainForm.Control.cs b/Netch/Forms/MainForm.Control.cs
index e70d477e..619dfece 100644
--- a/Netch/Forms/MainForm.Control.cs
+++ b/Netch/Forms/MainForm.Control.cs
@@ -23,15 +23,13 @@ namespace Netch.Forms
// 服务器、模式 需选择
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"),
- MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
return;
}
if (ModeComboBox.SelectedIndex == -1)
{
- MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"),
- MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select an mode first"));
return;
}
@@ -56,7 +54,7 @@ namespace Netch.Forms
//LastDownloadBandwidth = 0;
//UploadSpeedLabel.Text = "↑: 0 KB/s";
DownloadSpeedLabel.Text = "↑↓: 0 KB/s";
- UsedBandwidthLabel.Text = $"{i18N.Translate("Used")}{i18N.Translate(": ")}0 KB";
+ UsedBandwidthLabel.Text = $"{i18N.Translate("Used",": ")}0 KB";
UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = true;
@@ -201,7 +199,7 @@ namespace Netch.Forms
}
UsedBandwidthLabel.Text =
- $"{i18N.Translate("Used")}{i18N.Translate(": ")}{Bandwidth.Compute(upload + download)}";
+ $"{i18N.Translate("Used",": ")}{Bandwidth.Compute(upload + download)}";
UploadSpeedLabel.Text = $"↑: {Bandwidth.Compute(upload - LastUploadBandwidth)}/s";
DownloadSpeedLabel.Text = $"↓: {Bandwidth.Compute(download - LastDownloadBandwidth)}/s";
diff --git a/Netch/Forms/MainForm.MenuStrip.cs b/Netch/Forms/MainForm.MenuStrip.cs
index 6451dcf0..b344ac50 100644
--- a/Netch/Forms/MainForm.MenuStrip.cs
+++ b/Netch/Forms/MainForm.MenuStrip.cs
@@ -38,7 +38,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Import servers error!"), i18N.Translate("Error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ MessageBoxX.Show(i18N.Translate("Import servers error!"), info: false);
}
InitServer();
@@ -106,7 +106,7 @@ namespace Netch.Forms
// 当前 ServerComboBox 中至少有一项
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
return;
}
@@ -213,7 +213,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("No subscription link"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("No subscription link"));
}
}
@@ -249,7 +249,7 @@ namespace Netch.Forms
NFAPI.nf_registerDriver("netfilter2");
}
- MessageBox.Show(this, i18N.Translate("Service has been restarted"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Service has been restarted"), owner: this);
Enabled = true;
});
}
@@ -284,16 +284,16 @@ namespace Netch.Forms
File.Delete(driver);
- MessageBox.Show(this, i18N.Translate("Service has been uninstalled"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Service has been uninstalled"), owner: this);
}
catch (Exception ex)
{
- MessageBox.Show(this, i18N.Translate("Error") + i18N.Translate(": ") + ex, i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Error") + i18N.Translate(": ") + ex, info: false, owner: this);
}
}
else
{
- MessageBox.Show(this, i18N.Translate("Service has been uninstalled"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Service has been uninstalled"), owner: this);
}
Enabled = true;
@@ -308,7 +308,7 @@ namespace Netch.Forms
{
InitMode();
- MessageBox.Show(this, i18N.Translate("Modes have been reload"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Modes have been reload"), owner: this);
Enabled = true;
});
}
@@ -320,7 +320,7 @@ namespace Netch.Forms
{
DNS.Cache.Clear();
- MessageBox.Show(this, i18N.Translate("DNS cache cleanup succeeded"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("DNS cache cleanup succeeded"), owner: this);
StatusText(i18N.Translate("DNS cache cleanup succeeded"));
Enabled = true;
});
@@ -366,7 +366,7 @@ namespace Netch.Forms
// 当前 ServerComboBox 中至少有一项
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
return;
}
@@ -399,7 +399,7 @@ namespace Netch.Forms
catch (Exception e)
{
Logging.Info("使用代理更新 ACL 失败!" + e.Message);
- MessageBox.Show(i18N.Translate("ACL update failed") + "\n" + e.Message);
+ MessageBoxX.Show(i18N.Translate("ACL update failed") + "\n" + e.Message);
}
finally
{
@@ -421,7 +421,7 @@ namespace Netch.Forms
// 未开启自动停止
if (!Global.Settings.StopWhenExited)
{
- MessageBox.Show(i18N.Translate("Please press Stop button first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please press Stop button first"));
Visible = true;
ShowInTaskbar = true; // 显示在系统任务栏
@@ -479,7 +479,7 @@ namespace Netch.Forms
else
{
Logging.Info("ACL 更新失败!" + args.Error);
- MessageBox.Show(i18N.Translate("ACL update failed") + "\n" + args.Error);
+ MessageBoxX.Show(i18N.Translate("ACL update failed") + "\n" + args.Error);
}
}
finally
diff --git a/Netch/Forms/MainForm.Misc.cs b/Netch/Forms/MainForm.Misc.cs
index 941df06b..7bc514e7 100644
--- a/Netch/Forms/MainForm.Misc.cs
+++ b/Netch/Forms/MainForm.Misc.cs
@@ -21,7 +21,7 @@ namespace Netch.Forms
{
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- $"{i18N.Translate(@"New version available")}{i18N.Translate(@": ")}{updater.LatestVersionNumber}",
+ $"{i18N.Translate(@"New version available",": ")}{updater.LatestVersionNumber}",
ToolTipIcon.Info);
};
updater.Check(false, false);
diff --git a/Netch/Forms/MainForm.Profile.cs b/Netch/Forms/MainForm.Profile.cs
index 528886a6..ac1067b2 100644
--- a/Netch/Forms/MainForm.Profile.cs
+++ b/Netch/Forms/MainForm.Profile.cs
@@ -141,15 +141,15 @@ namespace Netch.Forms
{
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
}
else if (ModeComboBox.SelectedIndex == -1)
{
- MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select an mode first"));
}
else if (ProfileNameText.Text == "")
{
- MessageBox.Show(i18N.Translate("Please enter a profile name first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please enter a profile name first"));
}
else
{
@@ -161,7 +161,7 @@ namespace Netch.Forms
{
if (ProfileButtons[index].Text == i18N.Translate("Error") || ProfileButtons[index].Text == i18N.Translate("None"))
{
- MessageBox.Show(i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button"));
}
try
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index 4b269e83..16259004 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -224,12 +224,14 @@ namespace Netch.Forms
ProfileGroupBox.Text = i18N.Translate("Profiles");
// 加载翻译
- UsedBandwidthLabel.Text = $@"{i18N.Translate("Used")}{i18N.Translate(": ")}0 KB";
+ UsedBandwidthLabel.Text = $@"{i18N.Translate("Used", ": ")}0 KB";
UpdateStatus();
VersionLabel.Text = UpdateChecker.Version;
}
- #region MISC
+
+ #region MISC
+
///
/// 监听电源事件,自动重启Netch服务
///
@@ -285,7 +287,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
}
}
@@ -324,7 +326,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select an mode first"));
}
}
@@ -349,7 +351,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select an mode first"));
}
}
@@ -370,7 +372,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
}
}
@@ -393,7 +395,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please select a server first"));
}
}
diff --git a/Netch/Forms/Mode/Process.cs b/Netch/Forms/Mode/Process.cs
index dab1f9c1..b149bd46 100644
--- a/Netch/Forms/Mode/Process.cs
+++ b/Netch/Forms/Mode/Process.cs
@@ -167,7 +167,7 @@ namespace Netch.Forms.Mode
}
else
{
- MessageBox.Show(i18N.Translate("Please enter an process name (xxx.exe)"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please enter an process name (xxx.exe)"));
}
}
@@ -185,7 +185,7 @@ namespace Netch.Forms.Mode
if (dialog.ShowDialog(Win32Native.GetForegroundWindow()) == CommonFileDialogResult.Ok)
{
ScanDirectory(dialog.FileName);
- MessageBox.Show(i18N.Translate("Scan completed"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Scan completed"));
}
}
@@ -222,14 +222,14 @@ namespace Netch.Forms.Mode
File.WriteAllText(Path.Combine("mode", FilenameTextBox.Text) + ".txt", text);
- MessageBox.Show(i18N.Translate("Mode updated successfully"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Mode updated successfully"));
Global.MainForm.UpdateMode(mode, EditMode_Old);
Close();
}
else
{
- MessageBox.Show(i18N.Translate("Unable to add empty rule"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Unable to add empty rule"));
}
}
else
@@ -258,7 +258,7 @@ namespace Netch.Forms.Mode
{
if (Global.Settings.ModeFileNameType == 0 && string.IsNullOrWhiteSpace(FilenameTextBox.Text))
{
- MessageBox.Show(i18N.Translate("Please enter a mode filename"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please enter a mode filename"));
return;
}
var ModeFilename = Path.Combine("mode", FilenameTextBox.Text);
@@ -266,7 +266,7 @@ namespace Netch.Forms.Mode
// 如果文件已存在,返回
if (File.Exists(ModeFilename + ".txt"))
{
- MessageBox.Show(i18N.Translate("File already exists.\n Please Change the filename"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("File already exists.\n Please Change the filename"));
return;
}
@@ -297,19 +297,19 @@ namespace Netch.Forms.Mode
File.WriteAllText(ModeFilename + ".txt", text);
- MessageBox.Show(i18N.Translate("Mode added successfully"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Mode added successfully"));
Global.MainForm.AddMode(mode);
Close();
}
else
{
- MessageBox.Show(i18N.Translate("Unable to add empty rule"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Unable to add empty rule"));
}
}
else
{
- MessageBox.Show(i18N.Translate("Please enter a mode remark"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please enter a mode remark"));
}
}
}
diff --git a/Netch/Forms/Server/Shadowsocks.cs b/Netch/Forms/Server/Shadowsocks.cs
index 7c199311..2847093b 100644
--- a/Netch/Forms/Server/Shadowsocks.cs
+++ b/Netch/Forms/Server/Shadowsocks.cs
@@ -121,7 +121,7 @@ namespace Netch.Forms.Server
}
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/ShadowsocksR.cs b/Netch/Forms/Server/ShadowsocksR.cs
index f12f5a65..1753457c 100644
--- a/Netch/Forms/Server/ShadowsocksR.cs
+++ b/Netch/Forms/Server/ShadowsocksR.cs
@@ -141,7 +141,7 @@ namespace Netch.Forms.Server
}
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/Socks5.cs b/Netch/Forms/Server/Socks5.cs
index 95116237..05b4c7cb 100644
--- a/Netch/Forms/Server/Socks5.cs
+++ b/Netch/Forms/Server/Socks5.cs
@@ -104,7 +104,7 @@ namespace Netch.Forms.Server
}
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/Trojan.cs b/Netch/Forms/Server/Trojan.cs
index 26c3c168..e2042dbd 100644
--- a/Netch/Forms/Server/Trojan.cs
+++ b/Netch/Forms/Server/Trojan.cs
@@ -100,7 +100,7 @@ namespace Netch.Forms.Server
}
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/Vmess.cs b/Netch/Forms/Server/Vmess.cs
index 77743577..9cebf0ff 100644
--- a/Netch/Forms/Server/Vmess.cs
+++ b/Netch/Forms/Server/Vmess.cs
@@ -119,7 +119,7 @@ namespace Netch.Forms.Server
}
if (AlterIDTextBox.Text == "")
{
- MessageBox.Show(i18N.Translate("Please fill in alterID"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Please fill in alterID"));
return;
}
if (Index == -1)
@@ -167,7 +167,7 @@ namespace Netch.Forms.Server
}
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs
index a1f07e62..99aad7dd 100644
--- a/Netch/Forms/SettingForm.cs
+++ b/Netch/Forms/SettingForm.cs
@@ -228,7 +228,7 @@ namespace Netch.Forms
catch (FormatException)
{
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
- MessageBox.Show(i18N.Translate("Port value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Port value illegal. Try again."));
return;
}
@@ -249,7 +249,7 @@ namespace Netch.Forms
catch (FormatException)
{
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
- MessageBox.Show(i18N.Translate("Port value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Port value illegal. Try again."));
return;
}
@@ -270,7 +270,7 @@ namespace Netch.Forms
catch (FormatException)
{
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
- MessageBox.Show(i18N.Translate("Port value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Port value illegal. Try again."));
return;
}
@@ -298,7 +298,7 @@ namespace Netch.Forms
}
catch (FormatException)
{
- MessageBox.Show(i18N.Translate("IP address format illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("IP address format illegal. Try again."));
TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address;
TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask;
@@ -332,7 +332,7 @@ namespace Netch.Forms
catch (FormatException)
{
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- MessageBox.Show(i18N.Translate("ProfileCount value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("ProfileCount value illegal. Try again."));
return;
}
@@ -355,7 +355,7 @@ namespace Netch.Forms
catch (FormatException)
{
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- MessageBox.Show(i18N.Translate("STUN_ServerPort value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("STUN_ServerPort value illegal. Try again."));
return;
}
@@ -377,7 +377,7 @@ namespace Netch.Forms
catch (FormatException)
{
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- MessageBox.Show(i18N.Translate("Detection interval value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Detection interval value illegal. Try again."));
return;
}
@@ -399,7 +399,7 @@ namespace Netch.Forms
Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked;
Configuration.Save();
- MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Saved"));
Close();
}
}
diff --git a/Netch/Forms/SubscribeForm.cs b/Netch/Forms/SubscribeForm.cs
index 812d847b..aa328320 100644
--- a/Netch/Forms/SubscribeForm.cs
+++ b/Netch/Forms/SubscribeForm.cs
@@ -83,7 +83,7 @@ namespace Netch.Forms
}
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
{
- if (MessageBox.Show(i18N.Translate("Delete or not ? Will clean up the corresponding group of items in the server list"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
+ if (MessageBoxX.Show(i18N.Translate("Delete or not ? Will clean up the corresponding group of items in the server list"), confirm: true) == DialogResult.OK)
{
if (SubscribeLinkListView.SelectedItems.Count > 0)
{
@@ -161,7 +161,7 @@ namespace Netch.Forms
Configuration.Save();
Global.Settings.UseProxyToUpdateSubscription = UseSelectedServerCheckBox.Checked;
- MessageBox.Show(i18N.Translate("Successfully saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Successfully saved"));
}
});
if (saveFlag)
@@ -182,17 +182,17 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(i18N.Translate("Links must start with http:// or https://"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Links must start with http:// or https://"));
}
}
else
{
- MessageBox.Show(i18N.Translate("Link can not be empty"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Link can not be empty"));
}
}
else
{
- MessageBox.Show(i18N.Translate("Remark can not be empty"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Remark can not be empty"));
}
}
@@ -200,7 +200,7 @@ namespace Netch.Forms
{
Configuration.Save();
Global.Settings.UseProxyToUpdateSubscription = UseSelectedServerCheckBox.Checked;
- MessageBox.Show(i18N.Translate("Successfully saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Successfully saved"));
Close();
}
///
diff --git a/Netch/Netch.cs b/Netch/Netch.cs
index 3f59d94e..f9f28aad 100644
--- a/Netch/Netch.cs
+++ b/Netch/Netch.cs
@@ -62,7 +62,7 @@ namespace Netch
if (!mutex.WaitOne(0, false))
{
// 弹出提示
- MessageBox.Show(i18N.Translate("Netch is already running"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show(i18N.Translate("Netch is already running"));
// 退出进程
Environment.Exit(1);
@@ -76,7 +76,7 @@ namespace Netch
{
// 弹出提示
- MessageBox.Show($"{i18N.Translate("Netch is not compatible with your system.")}\n{i18N.Translate("Current arch of Netch:")} {PROC}\n{i18N.Translate("Current arch of system:")} {OS}", i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show($"{i18N.Translate("Netch is not compatible with your system.")}\n{i18N.Translate("Current arch of Netch:")} {PROC}\n{i18N.Translate("Current arch of system:")} {OS}");
// 退出进程
Environment.Exit(1);
diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs
index d9531358..229ad5f6 100644
--- a/Netch/Utils/Configuration.cs
+++ b/Netch/Utils/Configuration.cs
@@ -69,7 +69,7 @@ namespace Netch.Utils
else
{
// 弹出提示
- MessageBox.Show("如果你是第一次使用本软件\n请务必前往http://netch.org 安装程序所需依赖,\n否则程序将无法正常运行!", i18N.Translate("注意!"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBoxX.Show("如果你是第一次使用本软件\n请务必前往http://netch.org 安装程序所需依赖,\n否则程序将无法正常运行!", i18N.Translate("注意!"));
// 创建 data 文件夹并保存默认设置
Save();
@@ -164,7 +164,7 @@ namespace Netch.Utils
if (string.IsNullOrEmpty(Global.TUNTAP.ComponentID))
{
Logging.Info("未找到可用 TUN/TAP 适配器");
- if (MessageBox.Show(i18N.Translate("TUN/TAP driver is not detected. Is it installed now?"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
+ if (MessageBoxX.Show(i18N.Translate("TUN/TAP driver is not detected. Is it installed now?"),confirm:true) == DialogResult.OK)
{
addtap();
//给点时间,不然立马安装完毕就查找适配器可能会导致找不到适配器ID
@@ -175,7 +175,7 @@ namespace Netch.Utils
{
return false;
}
- //MessageBox.Show(i18N.Translate("Please install TAP-Windows and create an TUN/TAP adapter manually"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ //MessageBoxX.Show(i18N.Translate("Please install TAP-Windows and create an TUN/TAP adapter manually"));
// return false;
}
diff --git a/Netch/Utils/MessageBoxX.cs b/Netch/Utils/MessageBoxX.cs
new file mode 100644
index 00000000..c5008968
--- /dev/null
+++ b/Netch/Utils/MessageBoxX.cs
@@ -0,0 +1,24 @@
+using System.Windows.Forms;
+
+namespace Netch.Utils
+{
+ class MessageBoxX
+ {
+ ///
+ ///
+ /// 内容
+ /// 自定义标题
+ /// 弹窗等级 (标题, 图标)
+ /// 需要确认
+ /// 阻止 owner Focus() 直到 Messageox 被关闭
+ public static DialogResult Show(string text, string title = "", bool info = true, bool confirm = false,IWin32Window owner = null)
+ {
+ return MessageBox.Show(
+ owner: owner,
+ text: i18N.Translate(text: text),
+ caption: i18N.Translate(string.IsNullOrWhiteSpace(title) ? (info ? "Information" : "Error") : title),
+ buttons: confirm ? MessageBoxButtons.OKCancel : MessageBoxButtons.OK,
+ icon: info ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);
+ }
+ }
+}
\ No newline at end of file