I am using a ListBox (lbChat) as a chat box for the chat text of my chatting application - simply put when a user sends the server a message it is written (added) to the chat listbox as so:
Where (stext) is a string of text that will be displayed, something like "Player1: Has Joined the Game" or "Player2: How was lunch?", etc.. you get the idea...
(quick note - I am using the LISTBOX because I thought it was the best control to use - if you have other suggestions that would be better then a listbox I am all ears...)
So, the way it works - Clients send text to the servers TCP Listener Threads which pick them up and then add them to the servers listbox (lbChat) as chat text using the method shown above.
The next step for me was now getting the SERVER to send the message to all the clients so that everyone sees the text - for this I was planning on using the ListBox Properties... (but running into trouble with that now)...
Now what I was planning on doing was - when Text is added to the Listbox (using the method shown above) I would use an event triggered but the fact that I just ADDED TEXT and use that event to send the ADDED TEXT to every client on my list...
This causes me two problems - a) I can't seem to find a LISTBOX EVENT fired everytime I add text and b) how would I get a copy of the text added to the listbox? I need something like "string sNewText = lbChat.LastLine" or something, I suppose I could use indexes or lenghts or something...
Anyways - without the EVENT this method won't work....
Any ideas, hints, and help would be greatly appreciated, thanks
Code:
lbChatBox.Items.Add(stext);
(quick note - I am using the LISTBOX because I thought it was the best control to use - if you have other suggestions that would be better then a listbox I am all ears...)
So, the way it works - Clients send text to the servers TCP Listener Threads which pick them up and then add them to the servers listbox (lbChat) as chat text using the method shown above.
The next step for me was now getting the SERVER to send the message to all the clients so that everyone sees the text - for this I was planning on using the ListBox Properties... (but running into trouble with that now)...
Now what I was planning on doing was - when Text is added to the Listbox (using the method shown above) I would use an event triggered but the fact that I just ADDED TEXT and use that event to send the ADDED TEXT to every client on my list...
This causes me two problems - a) I can't seem to find a LISTBOX EVENT fired everytime I add text and b) how would I get a copy of the text added to the listbox? I need something like "string sNewText = lbChat.LastLine" or something, I suppose I could use indexes or lenghts or something...
Anyways - without the EVENT this method won't work....
Any ideas, hints, and help would be greatly appreciated, thanks