Просмотр исходного кода

Merge branch 'master' of http://gogs.efunbox.cn:3000/Rankin/WinBox.git

zhouxianguang 6 лет назад
Родитель
Сommit
e68607318d
2 измененных файлов с 53 добавлено и 2 удалено
  1. 2 0
      WinBox/MainForm.Designer.cs
  2. 51 2
      WinBox/MainForm.cs

+ 2 - 0
WinBox/MainForm.Designer.cs

@@ -45,6 +45,8 @@
             this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
             this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
             this.Load += new System.EventHandler(this.Form1_Load);
+            this.Activated += new System.EventHandler(this.Form1_Activated);
+            
             this.ResumeLayout(false);
 
         }

+ 51 - 2
WinBox/MainForm.cs

@@ -45,6 +45,57 @@ namespace WinBox
            // RunBat("C:\\Lingjiao\\winBoxNode\\start.bat");
         }
 
+        private void Form1_Activated(object sender, System.EventArgs e)
+        {
+            // Label1.Text = "x: " + x + " y: " + y;
+            // Label2.Text = "Number of forms currently open: " + count;
+
+            string tcpPort = "9191";
+            try
+            {
+                if (tcpPort == "" || tcpPort == null)
+                {
+                    MessageBox.Show("请输入TCP端口号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+                }
+                else
+                {
+                    Process process = new Process();
+                    process.StartInfo = new ProcessStartInfo("netstat", "/ano");
+                    process.StartInfo.CreateNoWindow = true;
+                    process.StartInfo.UseShellExecute = false;
+                    process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+                    process.StartInfo.RedirectStandardOutput = true;
+                    process.Start();
+                    StreamReader reader = process.StandardOutput;
+                    while (!reader.EndOfStream)
+                    {
+                        string msg = reader.ReadLine().ToUpper();
+                        if (msg.IndexOf("TCP") > 0 && msg.IndexOf(":" + tcpPort) > 0)
+                        {
+                            string info = msg.Trim();
+                            MessageBox.Show("TCP:" + tcpPort + "端口被占用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+                            break;
+                        }
+                        else
+                        {
+                            MessageBox.Show("TCP:" + tcpPort + "端口没有被占用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+                            break;
+                        }
+                    }
+                    
+                    reader.Close();
+                    process.Close();
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("检测TCP端口:" + tcpPort + "失败!" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+            }
+
+
+
+        }
+
         private void RunBat(string batPath)
         {
             Process pro = new Process();
@@ -59,8 +110,6 @@ namespace WinBox
 
         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
         {
-           
-           
         }
 
         /// <summary>