Odd Behaviour with Lines in TextBox and .AppendText() - C#
I'm currently following the great tutorial on Geekpedia to create my own Chat Client and Chat Server.
Connecting the clients to the server works fine but I'm experiencing a few issues with the text being displayed in the chat log.
The first message that is displayed is in the Server window then the incoming connections are monitored:
Then I go to connect the Client to the host, all is fine and the appropriate log messages are displayed:
Now when I go to send a simple message the Line.Length property shows 3, in开发者_高级运维 particular notice the text:
Also, the .Text property contains everything, not just the current line:
Now looking at the Server and Client window you'll notice the text has some how copied itself in the wrong places and the previous message is overwritten:
If I press the Send button again (With the same string/message) I notice this in the debugger:
The text in the Server window does not move further down the box, it seems to overwrite what was previously there. Also the text in the Client window has gone:
So if I press the send text button again we see this for the Line property:
I'm at a complete loss, I spent a good few hours debugging the code and even after using a diff tool to compare the original code to mine it's all the same (With exception to certain words in different cases).
If I run the original source code and inspect the same Length property I notice that the count is 1 and the .Text property is only one line:
Everything displays correctly:
Does anybody have any idea what's going on? Now I know an option is to simply use the source code itself but I want to "learn by doing" and would like to know why this is happening and how to fix it.
Thanks for your time!
I am just taking a shot in the dark here, but the SendMessage method in your modified code uses the text from the chatWindow control. The SendMessage in the original code uses the text from txtMessage. I think you are using the text from the wrong control.
精彩评论