From 59e8bce99921cd63f6b1ae762d9ba6cdc47de4b4 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Fri, 29 Nov 2019 23:01:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=EF=BC=8C=E5=85=B3=E9=94=AE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=A2=9E=E5=8A=A0=E4=BA=8C=E6=AC=A1=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FrpClient-Win/AddItemDlg.cs | 6 ++++-- FrpClient-Win/Form1.cs | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/FrpClient-Win/AddItemDlg.cs b/FrpClient-Win/AddItemDlg.cs index fac4930..05f8623 100644 --- a/FrpClient-Win/AddItemDlg.cs +++ b/FrpClient-Win/AddItemDlg.cs @@ -57,8 +57,10 @@ public void InitShow(string strSectionName = null) private void DeleteItem_Click(object sender, System.EventArgs e) { - DB.Instance().DelItem(cNewItemInfo.strSectionName); - Close(); + if(MessageBox.Show("确定要删除吗?", "删除条目", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { + DB.Instance().DelItem(cNewItemInfo.strSectionName); + Close(); + } } private void InputAddLoaclIP_DoubleClick(object sender, EventArgs e) { diff --git a/FrpClient-Win/Form1.cs b/FrpClient-Win/Form1.cs index 29caecb..e26faca 100644 --- a/FrpClient-Win/Form1.cs +++ b/FrpClient-Win/Form1.cs @@ -109,7 +109,7 @@ private void RestartService_Click(object sender, EventArgs e) private void MyProcOutputHandler(object sendingProcess,DataReceivedEventArgs outLine) { if(!String.IsNullOrEmpty(outLine.Data)) { - ProcOutput.Text += outLine.Data.ToString()+"\r\n"; + ProcOutput.AppendText(outLine.Data.ToString() + "\r\n"); ProcOutput.SelectionStart = ProcOutput.Text.Length; ProcOutput.ScrollToCaret(); } @@ -171,11 +171,15 @@ private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) { this.Show(); this.Activate(); this.ShowInTaskbar = true; + ProcOutput.ScrollToCaret(); } } + private void Exit_toolStripMenuItem_Click(object sender, EventArgs e) { - CloseFrp(); - Application.Exit(); + if(MessageBox.Show("确定要退出吗?", "退出程序", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK){ + CloseFrp(); + Application.Exit(); + } } private void AutoRun_Click(object sender, EventArgs e) From e5f586eaf0ff2fd5301d2c10d0098e002c62ee27 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Wed, 24 Jun 2020 12:37:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=8C=E7=9B=AE=E5=BD=95=E4=B8=8D?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=A4=9A=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FrpClient-Win/Form1.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/FrpClient-Win/Form1.cs b/FrpClient-Win/Form1.cs index 4a9b0e9..09665aa 100644 --- a/FrpClient-Win/Form1.cs +++ b/FrpClient-Win/Form1.cs @@ -35,6 +35,12 @@ private void OnMainFormLoad(object sender, EventArgs e) { System.IO.Directory.SetCurrentDirectory(System.Windows.Forms.Application.StartupPath); + // 检查同目录多开 + if(IsDuplicateInstance()){ + MessageBox.Show("本程序已经在运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); + Application.Exit(); + } + InitList(true); UpdateStartButton(); //notifyIcon.Icon = this.Icon; @@ -53,6 +59,17 @@ private void OnMainFormLoad(object sender, EventArgs e) } } + // 检查是否多开 + private static bool IsDuplicateInstance() { + bool bCreatedNew; + // 允许不同目录实例 + string name = System.Windows.Forms.Application.StartupPath; + name = name.Replace("\\", "/"); + //创建Mutex互斥对象 + System.Threading.Mutex newMutex = new System.Threading.Mutex(true, name, out bCreatedNew); + return !bCreatedNew; + } + private void InitList(bool bReadConfig = false) { if(bReadConfig)