private void sendMessageToChatWindow(String friendName, String msgBody) { foreach (frmMessageWindow chatWindow in chatWindowsList) { if (chatWindow.getFriendsName().Equals(friendName)) { if (chatWindow.IsDisposed) { chatWindowsList.Remove(chatWindow); break; } chatWindow.receiveMessage(msgBody); chatWindow.Refresh(); return; } } frmMessageWindow newChatWindow = new frmMessageWindow(friendName); newChatWindow.receiveMessage(msgBody); newChatWindow.Show(); chatWindowsList.Add(newChatWindow); //if (chatWindows[windowNo] == null) //{ // chatWindows[windowNo] = new frmMessageWindow(friendName); //} //else //{ // if (chatWindows[windowNo].IsDisposed) // chatWindows[windowNo] = new frmMessageWindow(friendName); //} //if (chatWindows[windowNo].Visible == false) //{ // chatWindows[windowNo].Show(); //} //chatWindows[windowNo].receiveMessage(msgBody); //chatWindows[windowNo].Refresh(); //chatWindows[windowNo].BringToFront(); //chatWindows[windowNo].Focus(); }
private void lvFriends_MouseDoubleClick(object sender, MouseEventArgs e) { if (lvFriends.SelectedIndices.Count==0) { return; } int offest = lvFriends.SelectedIndices[0]; if (!friendStatus[offest]) { //return // temp disabled } foreach (frmMessageWindow chatWindow in chatWindowsList) { if (chatWindow.getFriendsName().Equals(friends[offest])) { if (chatWindow.IsDisposed) { chatWindowsList.Remove(chatWindow); break; } chatWindow.Visible = true; chatWindow.BringToFront(); chatWindow.Focus(); return; } } frmMessageWindow newChatWindow = new frmMessageWindow(friends[offest]); chatWindowsList.Add(newChatWindow); newChatWindow.Show(); //if (chatWindows[offest] == null) //{ // chatWindows[offest] = new frmMessageWindow(friends[offest]); //} //else //{ // if (chatWindows[offest].IsDisposed) // chatWindows[offest] = new frmMessageWindow(friends[offest]); //} //chatWindows[offest].Show(); //chatWindows[offest].BringToFront(); //chatWindows[offest].Focus(); }