コード例 #1
0
        private void AppendMyMessage(string message)
        {
            StringBuilder strBl = new StringBuilder();

            strBl.Append(_workWithMessage.MyNickName).Append(": ").Append(message).Append("\n");
            TextBox_Chat.AppendText(strBl.ToString());
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 private void Button_Disconnect_Click(object sender, EventArgs e)
 {
     if (comPort != null)
     {
         comPort.Close();
         comPort = null;
         TextBox_Chat.AppendText("You are disconnected." + Environment.NewLine);
     }
 }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 private void DataReceived(object sender, EventArgs e)
 {
     TextBox_Chat.AppendText(comPort.ReadExisting() + Environment.NewLine);
 }
コード例 #8
0
 private void ErrorReceived(object sender, EventArgs e)
 {
     TextBox_Chat.AppendText("Error Received!" + Environment.NewLine);
 }