Hey, I was wondering if any of you know how to fix a error I get in my chat client I made. The error is that when you hit ctrl + enter into the box that you type your text in, and you hit enter it just sends the username and a bunch of blank text where no text has been entered. I was wondering if there was a way to fix this problem to where the client will not send all the blank text, just make it to where it will not send it at all unless there is text in the box. Here is what the code looks like private void rtbTalk_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == 13)
{
if(m_sock == null || !m_sock.Connected)
{
MessageBox.Show( this, "Must be connected to send a message" );
return;
}
try
{
string Message;
Message = Username + ":" + " " + rtbTalk.Text;
Byte [] byteDateLine = Encoding.ASCII.GetBytes( Message.ToCharArray() );
m_sock.Send( byteDateLine, byteDateLine.Length, 0 );
rtbTalk.Text = "";
}
catch(Exception ex)
{
MessageBox.Show( this, ex.Message, "Send message failed!" );
}
}
}
Any help would be greatly appreciated.