Link to home
Start Free TrialLog in
Avatar of matt_d_p
matt_d_p

asked on

Newbie delegate question - how to declare

Hi

I have an windows form app with a textbox. In a second class I have a socket server and client connection. The idea is when a connection is made to the server port the network stream is sent on through the client to a destination port. I would like to display this data (an xml message) along with any responses in the text box in my form. After searching it seems I need to use a delegate pointing to a method which will update the textbox. In my form I have created the method:

class Form1
{
....
public void update_txtBox(string data)
        {
            richTextBox1.AppendText(data);
        }
}

In the socket class I get the network stream and send it to the destination port but am struggling to write the data to the textbox.

class socket
{
public delegate void AddText(string data);
......
AddText updateTextBox = new AddText(Form1.update_txtBox);
.....
}

My questions:
Am I on the right track?
Do I declare the delegate in the form class or the socket class or either?
In which class do I declare the delegate variable and is my attempt above correct? (it doesn't work so probably not :)

Any help or a pointer to a good tutorial/explanation will be appreciated.

Matt
ASKER CERTIFIED SOLUTION
Avatar of Ravi Singh
Ravi Singh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matt_d_p
matt_d_p

ASKER

Thanks Zephyr__

This gives me a much clearer idea of what I need to do. Will read up a bit first and them have a go at implemeting it.
Matt