コード例 #1
0
ファイル: frmChatty.cs プロジェクト: CaterpillarCode/Chatty
        /// <summary>
        /// Sends a message to the server.
        /// </summary>
        private void BtnSend_Click(object sender, EventArgs e)
        {
            // If the message is valid.
            if (TbMsg.Text != string.Empty && TbMsg.Text != null)
            {
                string msg = TbMsg.Text;

                // If connected to the server.
                if (socket != null && socket.Connected)
                {
                    // If the message is not a command.
                    if (!RunCommand(msg))
                    {
                        // Convert the message into a byte array.
                        byte[] msgPayload = Encoding.ASCII.GetBytes(msg);

                        // Send the message asynchronously.
                        socket.SendAsync(msgPayload);

                        // Clears the message entry textbox.
                        TbMsg.Text = string.Empty;

                        // Display the message was sent.
                        AppendText($"\nYou: {msg}");
                    }
                }
                else
                {
                    MessageBox.Show("You are not connected to the server.");
                    TbMsg.Clear();
                }
            }
            else
            {
                //MessageBox.Show("Please enter a message before sending", "No Message To Send");
            }
        }
コード例 #2
0
ファイル: ScoreWnd.xaml.cs プロジェクト: zscboy/sloth-servers
 public void Clear()
 {
     TbMsg.Clear();
 }