using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Diaoyong { static class Program { [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)] private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ConnectionTest connectionTest = new ConnectionTest(); connectionTest.conf_Load(); connectionTest.StartPosition = FormStartPosition.CenterScreen; connectionTest.TopMost = true; connectionTest.Show(); connectionTest.UpdateLableStatus("正在测试连接..."); connectionTest.Refresh();//强制控件使其工作区无效并立即重绘自己和任何子控件 connectionTest.ConnectionTesting(); if (connectionTest.m_Done == false) { connectionTest.Close(); Form1 form = new Form1(); form.StartPosition = FormStartPosition.CenterScreen; Application.Run(form); } else { connectionTest.UpdateLableStatus("连接失败"); DialogResult dr = MessageBox.Show("连接超时,请检查IP地址和端口是否正确!", "连接失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }