/* * EVENT : server_button_Click() * * DESCRIPTION : This event is activated when user inputs a * server name. It is intended to let the user know they have connected * to the server. It will end by focusing on the message field allowing the * user to write in their intended message to other clients. * PARAMETERS : object : sender * : RoutedEventArgs : e * * RETURNS : N/A */ public void server_button_Click(object sender, RoutedEventArgs e) { if (userNameSelected == true) { if (!string.IsNullOrWhiteSpace(ServerNameTextBox.Text)) { //TAB STUFF connectedStatus = true; //Delay for 1 second System.Threading.Thread.Sleep(1000); //Insert new name to list box UpdateMasterList("C"); //Trigger series of connection events connectionServerFieldsFormattingEvents(); //Trigger series of tab formatting events connectionServerTabFormattingEvents(); //Focus on message field MessageField.Focus(); } else { MessageBox.Show("Please input a proper server name (Ex. 2A213-A05)"); } } else { MessageBox.Show("You cannot connect to a server without a user name selected."); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { // Attempts to send the message string message = MessageField.Text; if (message != "") { synchronizer.SendMessage(message); } MessageField.Text = ""; MessageField.Focus(); }
private void MessageField_KeyDown(object sender, KeyEventArgs e) { // If enter is pressed, attempts to send the message if (e.Key != Key.Enter) { return; } string message = MessageField.Text; if (message != "") { synchronizer.SendMessage(message); } MessageField.Text = ""; MessageField.Focus(); }
/* * 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 }