private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (client != null) { client.Close(); client = null; if (server == null) timer.Start(); return; } { if (dlg.ShowDialog() != DialogResult.OK) return; if (string.IsNullOrEmpty(dlg.IP) || string.IsNullOrEmpty(dlg.PlayerName)) return; client = new Networking.Client(); client.Tcp.PacketReceived += new Networking.NetworkReceivePacket(Tcp_PacketReceived); client.Udp.PacketReceived += new Networking.NetworkReceivePacket(Udp_PacketReceived); client.ConnectionStateChanged += new Networking.ClientConnectionStateChanged(client_ConnectionStateChanged); client.Connect(dlg.IP, dlg.PlayerName); if (!timer.Enabled) timer.Start(); } }