/* * EVENT : button2_Click() -- Send button is clicked * * DESCRIPTION : Determines which chat tab will recieve the message the local * user types. * PARAMETERS : object : sender * : RoutedEventArgs : e * * RETURNS : N/A */ public void button2_Click(object sender, RoutedEventArgs e) { if (connectedStatus == true) { if (!string.IsNullOrEmpty(MessageField.Text)) { messageText = MessageField.Text; //clear message field so it appears as though text as been sent and user can write again MessageField.Clear(); if (ClientListBox.SelectedItems.Count > 0) { if (guiPacketBuffer.MessageType.Equals("P")) { writeToPrivateChatTab(messageText); } else if (guiPacketBuffer.MessageType.Equals("G")) { writeToGroupChatTab(messageText); } else if (guiPacketBuffer.MessageType.Equals("B")) { writeToBroadcastChatTab(messageText); } //focus back on message field for user to write again MessageField.Focus(); } else { MessageBox.Show("You cannot chat if no clients are selected."); } } else { MessageBox.Show("Please compose a message."); } } else //there is no connection so you can't write anything { MessageBox.Show("You need to be connected to a server to write messages."); } // end of if }
/* * EVENT : button2_Copy_Click() * * DESCRIPTION : This button click event will clear the message field text box. * If the user has any text written in the text box it will prompt user before they * clear the content. * PARAMETERS : object : sender * : RoutedEventArgs : e * * RETURNS : N/A */ private void button2_Copy_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(MessageField.Text)) { MessageField.Clear(); //clear the message field. } else { MessageBoxResult result = MessageBox.Show("Would you like to clear your current message?", "Compose Message", MessageBoxButton.YesNo); switch (result) { //If user selects "Yes" in message box case MessageBoxResult.Yes: MessageField.Clear(); break; //If user selects "No" in message box case MessageBoxResult.No: break; } } }
/* * EVENT : Clear_Click() * * DESCRIPTION : this message clears the message field * if user clicks clear * PARAMETERS : object : sender * : RoutedEventArgs : e * * RETURNS : N/A */ private void Clear_Click(object sender, RoutedEventArgs e) { MessageField.Clear(); }