Hello, I have made two textboxes and a button, you type into the second textbox and it's content gets displayed on the first texbox when you click the button, and also creates a new line so I can type as much as I want without it clearing. I want to create an auto responder, so if I type something like "sup" it will respond saying "Hi" or something, without clearing the entire textbox.
Ive tried many different methods, they all seem to end up spamming.
if you are adding the reply to the same textbox then it will continue to spam the message..
First time you hit enter, textbox text = "lolsup" so code adds "\r\nClient: Hey".
Second time you hit enter the texbox text = "lolsup\r\nClient: Hey" so it still passes the If condition and adds "\r\nClient: Hey" again.
You need to do one of two things.
a) Instead of if (textBox1.Text.Contains("lolsup")) have it check only the last line for the matching text
b) Instead of checking for "lolsup" in textbox1 after you have added the user input, check the user input in textbox2, append if necesary, then transfer it to textbox1. Then clear textbox2 ready for the users next input. That way you are only checking the each input string once.
Am i right in thinking this is for some kind of instant messaging program? It sounds as though you are trying to produce an MSN-like interface, ie each line of text you type gets added to the bottom of the chat window and the automatic responses are added underneath like replies. If thats the case, i'd recommend that you rethink your program structure. Seperate the autoresponse code from the input code.
SO user enters text in textbox. When they click on a button the text is added to the chat window, but also passed to a method that checks for responses: