public partial class Form1 : Form
{
delegate void SetTextDelegate(Control control, string text);
public void SetText(Control control, string text)
{
if (this.InvokeRequired)
{
Invoke(new SetTextDelegate(SetText), new object[] { control, text });
}
else
{
control.Text = text;
}
}
}
public partial class Form2 : Form
{
void button1_Click(object sender, EventArgs e)
{
form1.SetText(form1.textbox1, "hello");
form1.SetText(form1.button1, "world");
}
}