private void AppendMyMessage(string message) { StringBuilder strBl = new StringBuilder(); strBl.Append(_workWithMessage.MyNickName).Append(": ").Append(message).Append("\n"); TextBox_Chat.AppendText(strBl.ToString()); }
private void AppendMyMessage(byte[] message) { StringBuilder strBl = new StringBuilder(); strBl.Append(_workWithMessage.MyNickName).Append(": ").Append(Encoding.UTF8.GetString(message)).Append("\n"); TextBox_Chat.AppendText(strBl.ToString()); }
private void Button_Send_Click(object sender, EventArgs e) { String message = TextBox_Message.Text; Send(message); TextBox_Chat.AppendText(message + Environment.NewLine); TextBox_Message.Clear(); }
private void Button_Disconnect_Click(object sender, EventArgs e) { if (comPort != null) { comPort.Close(); comPort = null; TextBox_Chat.AppendText("You are disconnected." + Environment.NewLine); } }
private void Button_Connect_Click(object sender, EventArgs e) { int i = ComboBox_Name.SelectedIndex; int j = ComboBox_Rate.SelectedIndex; bool isConnected = InitializePort(ComboBox_Name.Items[i].ToString(), Convert.ToInt32(ComboBox_Rate.Items[j])); if (isConnected == true) { TextBox_Chat.AppendText("You are connected." + Environment.NewLine); } }
private bool InitializePort(String name, int rate) { try { if (comPort != null) { return(false); } comPort = new SerialPort(name, rate, Parity.None, 8, StopBits.One); comPort.Open(); } catch (System.Exception ex) { comPort = null; TextBox_Chat.AppendText("Error: " + ex.Message + Environment.NewLine); return(false); } comPort.ErrorReceived += new SerialErrorReceivedEventHandler(ErrorReceived); comPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); return(true); }
private void DataReceived(object sender, EventArgs e) { TextBox_Chat.AppendText(comPort.ReadExisting() + Environment.NewLine); }
private void ErrorReceived(object sender, EventArgs e) { TextBox_Chat.AppendText("Error Received!" + Environment.NewLine); }