private void connectToolStripMenuItem_Click(object sender, EventArgs e)// Lorsque l'on clique sur Connect { if (!Connected) { if (FormMain.ipAddressServer != null || FormMain.port != -1) { finish = false; FormConnection formConnection = new FormConnection(); formConnection.OnCreateConnectingClient += formConnection_OnCreateConnectingClient; formConnection.ShowDialog(); } else { MessageBox.Show("Please first configure the server.\nGo to Menu > Parameters > Server IP Address."); } } else { // On coupe toutes les connexions foreach (FormChatRoom chatRoom in this.listFormChatRoom) { chatRoom.Close(); } foreach (FormChatPrivate privateChatRoom in this.listFormChatPrivate) { privateChatRoom.Close(); } listFormChatRoom.Clear(); listFormChatPrivate.Clear(); this.treeViewChatRooms.Nodes[0].Nodes.Clear(); this.treeViewClients.Nodes[0].Nodes.Clear(); ChatLib.MessageChat msg = new ChatLib.MessageChat(ChatLib.MessageType.DisconnectFromServer, client.UserName, null, null); ChatLib.ChatLib.SendMessage(client.ClientSocket, msg); } menuStrip_Update(); }
// Lorsque l'on clique sur Connect private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (!Connected) { if (FormMain.ipAddressServer != null || FormMain.port != -1) { finish = false; FormConnection formConnection = new FormConnection(); formConnection.OnCreateConnectingClient += formConnection_OnCreateConnectingClient; formConnection.ShowDialog(); } else { MessageBox.Show("Please first configure the server.\nGo to Menu > Parameters > Server IP Address."); } } else { // On coupe toutes les connexions foreach (FormChatRoom chatRoom in this.listFormChatRoom) { chatRoom.Close(); } foreach (FormChatPrivate privateChatRoom in this.listFormChatPrivate) { privateChatRoom.Close(); } listFormChatRoom.Clear(); listFormChatPrivate.Clear(); this.treeViewChatRooms.Nodes[0].Nodes.Clear(); this.treeViewClients.Nodes[0].Nodes.Clear(); ChatLib.MessageChat msg = new ChatLib.MessageChat(ChatLib.MessageType.DisconnectFromServer, client.UserName, null, null); ChatLib.ChatLib.SendMessage(client.ClientSocket, msg); } menuStrip_Update(); }