I actually dont understand what is wrong with your code based on your description.
Do you want to try to add text from some other class to textbox?
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
to "add" data to textBox you have to glue th text together by using "+=" operators:
textBox1.Text = "some text";
textBox1.Text += " new text";
//out put is "some text new text".
If you work over classes or maybe even threads, yes, you should use delegates to update textBox control.
In this case, create a new method, which will update textBox only. And pass the data to it:
public delegate void TextBoxDelegate(string message);
public void UpdatingTextBox(string msg)
{
if(textBox1.InvokeRequired)
textBox1.Invoke(new TextBoxDelegate(UpdatingTextBox), new object[]{ msg });
else
{
textBox1.Text = msg;
//in case if you want to ADD text to previuos one do:
//textBox1.Text += msg + " ";
}
//always call this method to show a text in textBox1, like:
string data1 = "some text";
UpdatingTextBox(data1);
//later ones again:
string data2 = "new text";
UpdatingTextBox(data2);
//and so on...
Hope this helps clarifying how to use delegates and updating controls with them.
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
1. all code goes in the class (form) where the contol (textBox) is.
2. Delegate name is optional, you choose it; what ever name you want; just make is reasonable
3. is you have to replace then use only equal mark "=".
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474