I am developing a C# win forms project ,I have one main GUI (name : Form1
) and a class (name :AnotherClass
) , i am just updating the GUI text box from AnotherClass
,application gets complied and runs successfully but still text Box on GUI not updated.
Here is my code :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
AnotherClass obj = new AnotherClass();
obj.updategui();
}
public void AppendText(String text)
{
if (this.InvokeRequired)
{
this.Invoke(new Action<string>(AppendText), new object[] { text });
return;
}
this.textBox1.Text += text;
}
AnotherClass
class AnotherClass
{
public void updategui()
{
Form1 mainform = new Form1();
mainform.AppendText("Say Hi");
}
}
Any One Having idea of why the GUI not updated ? please comment with your working code. Regards.