I have a UI Class with StatusBarPanels
Then I have another Class that is a thread.
I want this class thread to update the StatusBarPanels in the UI class.
But I get the error:
error CS0120: An object reference is required for the nonstatic field,
method, or property myNameSpace.Mai nForm.SetStatus BarText(string) '
Please help a old C# newbie...
Short version:
public class MainForm : System.Windows. Forms.Form
{
private System.Windows. Forms.StatusBar statusBar1;
private System.Windows. Forms.Panel panel1;
private System.Windows. Forms.StatusBar Panel statusBarPanel1 ;
private System.Windows. Forms.StatusBar Panel statusBarPanel2 ;
private System.Windows. Forms.StatusBar Panel statusBarPanel3 ;
private void MainForm_Load(o bject sender, System.EventArg s e)
{
thread1= new MyThread();
}
public void SetStatusBarTex t(string txt)
{
if (InvokeRequired )
{
BeginInvoke(new StringParameter Delegate(SetVek t1StatusBarText ), new
object[]{txt});
return;
}
this.statusBarP anel1.Text = txt;
}
}
public class MyThread
{
Thread myThread;
public MyThread()
{
ThreadStart threadEntry= new ThreadStart(thi s.beginThread);
myThread= new Thread(threadEn try);
myThread.Start( );
}
public void beginComliThrea d()
{
int a=0;
while(true)
{
Thread.Sleep(50 0);
MainForm.SetSta tusBarText(++a) ;
}