Dong Lam Trien

Dong Lam Trien

  • 826
  • 986
  • 149.1k

How public static declaration for Statusbar Control ?

Jun 7 2015 5:45 AM
In C# assuming I have 2 forms: form1 and form2. I open Form1 drag Statusbar Control into Form1 with the following declaration:
[code]
public static void LogStatusBar(string status)
{
try
{
statusBar1.Text = "Thông báo: " + status; // error message here
}
catch (Exception ex)
{
}
}
private void form1_Load(object sender, EventArgs e)
{
....
LogStatusBar(Message);
....
}
[/code]
Form1 run before and open form2, form2 will be used together with function LogStatusBar Form1 (...) I have declared above, and in this form2. I declare the following code:
[code]
try
{
....
}
catch (Exception ex)
{
form1.LogStatusBar(ex.Message);
}
[/code]
My question posed here as Rebuild Solution in statusBar1.Text error will not be public static because of it, according to my understanding of this, verbatim error: Error 1 An object reference is required for the nonstatic field, method, or property 'Vidu.form1.statusBar1'. I want to declare the control statusBar1 was dragging this into the public static Form1 themselves to declare how the band through household property.

Answers (1)