Hello,
I would like to edit textMain from Form1 via a static class on an other thread. But I get the following error:
An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.SetText(string)'
I simplified the example. Anybody who can help me?
Code:public partial class Form1 : Form { // Set text delegate public delegate void SetTextDelegate(string text); Thread trdTest; // Form1 public Form1() { InitializeComponent(); trdTest = new Thread(new ThreadStart(DoThread)); trdTest.Start(); } // Thread void DoThread() { StaticClass.EditGUI(); } // Change textbox text public void SetText(string text) { if (txtMain.InvokeRequired) { object[] params_list = new object[] { text }; txtMain.Invoke(new SetTextDelegate(SetText), params_list); } else { txtMain.Text = text; } } }Code:// Static class public static class StaticClass { public static void EditGUI() { Form1.SetText("test"); } }




Reply With Quote