0

So I'm trying to check if some files exist when the program is loading. And I'm having trouble with cross referencing different forms:

An object reference is required for the non-static field, method, or property 'OnePlus_One_Toolkit.Main.CMOS_check' This applies to all of the checks ran in the code below (from the splash):

        private void Splash_Load(object sender, EventArgs e)
    {
        Process p = new System.Diagnostics.Process();
        ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
        si.RedirectStandardInput = true;
        si.CreateNoWindow = true;
        si.UseShellExecute = false;
        si.FileName = "adb.exe";
        si.Arguments = "start-server";
        p = Process.Start(si);
        p.WaitForExit();
        if (!File.Exists("stock.zip"))
        {
            Main.flash_stock.Enabled = false;
            Main.CMOS_check.Text = "Download the zip!";
        }
        if (!File.Exists("OOS.zip"))
        {
            Main.flash_OOS.Enabled = false;
            Main.OOS_check.Text = "Download the zip!";
        }
        if (File.Exists("stock.zip"))
        { Main.CMOS_check.Text = ""; }
        if (File.Exists("OOS.zip"))
        { Main.OOS_check.Text = ""; }
        this.Close();
    }

How would I go about fixing this. Or even improve my object reference? And just some extra info the labels and buttons I want to change are set to internal. And the splash does run after the initialize from the primary main form. And the splash is run as a child.

The Main form calling code is below:

public Main()
        {
            InitializeComponent();
            Splash splash = new Splash();
            splash.ShowDialog();
        }

The code should check to see if the files exist, and if they don't change the respective labels in the main form.

iTechy
  • 283
  • 1
  • 3
  • 18

1 Answers1

1

This is occurring because you are trying to access those controls as if they are static controls while they are not. Also. there is no State management available in windows forms application.

See this link : C# - Winforms - Global Variables

This link is the solution that you might be looking for.

Hope this helps.

Community
  • 1
  • 1
Dhrumil
  • 3,221
  • 6
  • 21
  • 34
  • I followed up my static issue and it turns out I needed to remove the `this.x` in the designer and now it works a treat :) thanks for the help. Have an upvote. – iTechy May 26 '15 at 10:36