Sign in to follow this  
Shaitan00

Triggered ListBox event when items are added [C#/CS 2005]

Recommended Posts

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: [CODE] lbChatBox.Items.Add(stext); [/CODE] 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

Share this post


Link to post
Share on other sites
Why are you trying to merge client/server functionality with your listbox? When the server recieves the text from the client, the handling of sending it to all clients in the chat should be performed seperately from displaying the text on the server.

If anything, the server's chatbox should be running as a local client, allowing you to completely decouple the 2 and have the server act as a server, and the client/listbox do their job seperately.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this