private void Window_Closed(object sender, EventArgs e) { // 如果還沒登出,要登出 if (LoginIn) { Packet packet = new Packet(); packet.makePacketLogOut(); sendToServer(null, packet); LoginIn = false; } try { client.close(); } catch (Exception err) { Console.WriteLine(err.ToString()); } foreach (ChatWindow chatWindow in chatWindows) { chatWindow.Close(); } }