C# 创建一个加载表单并加载不同的表单

C# 创建一个加载表单并加载不同的表单,c#,winforms,C#,Winforms,我已经创建了一个加载表单,但我希望访问加载表单并加载不同的表单。我知道有一种方法可以实现这一点,但我认为的方法是创建另一个加载表单并访问另一个加载表单来加载不同的表单,即使加载表单的内容相同 我怎样才能做到这一点 这是装货单的代码: public Loading() { InitializeComponent(); this.timer1.Interval = SystemManager.RandomNumberGenerator(1000, 2000)

我已经创建了一个加载表单,但我希望访问加载表单并加载不同的表单。我知道有一种方法可以实现这一点,但我认为的方法是创建另一个加载表单并访问另一个加载表单来加载不同的表单,即使加载表单的内容相同

我怎样才能做到这一点

这是装货单的代码:

public Loading()
    {
        InitializeComponent();

        this.timer1.Interval = SystemManager.RandomNumberGenerator(1000, 2000);

        this.timer1.Tick += new EventHandler(this.CheckTimer);
    }

    private void Loading_Load(object sender, EventArgs e)
    {
        this.timer1.Start();
    }

    private void CheckTimer(object sender, EventArgs e)
    {
        uint timeLeft = 1;

        timeLeft--;

        if (timeLeft == 0)
        {
            this.timer1.Stop();

            this.Hide();

            AgeConfirmation _ageConfirmation = new AgeConfirmation();

            _ageConfirmation.ShowDialog();

            this.Close();
        }
    }
上面的代码是一个加载表单,在达到0时加载另一个表单

我试过这样做:

public class SystemManager
{
public static void LoadForm(Form _form = null, Form _loadForm = null)
{
   _form.Hide();

   _loadForm = new Form();

   _loadForm.ShowDialog();

   _form.Close();
}
}
public class UserInformation
{
    public static int Value
    {
        get;
        set;
    }
}

public partial class Loading : Form
{
    public Loading()
    {
        InitializeComponent();

        this.timer1.Interval = SystemManager.RandomNumberGenerator(1000, 2000);

        this.timer1.Tick += new EventHandler(this.CheckTimer);
    }

    private void Loading_Load(object sender, EventArgs e)
    {
        this.timer1.Start();
    }

    private void CheckTimer(object sender, EventArgs e)
    {
        uint timeLeft = 1;

        timeLeft--;

        if (timeLeft == 0)
        {
            this.timer1.Stop();

            this.Hide();

            switch (UserInformation.Value)
            {
                case 0:
                AgeConfirmation _ageConfirmation = new AgeConfirmation();

                _ageConfirmation.ShowDialog();
                break;

                case 1:
                MainForm _mainForm = new MainForm();

                _mainForm.ShowDialog();
                break;

                case 2:
                Event _event = new Event();

                _event.ShowDialog();
                break;
            }

            this.Close();
        }
    }
}

private void AgeConfirmation_Load(object sender, EventArgs e)
    {
        UserInformation.Value = 1;
    }

private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();

        Loading _loading = new Loading();

        _loading.ShowDialog();

        this.Close();
    }

private void MainForm_Load(object sender, EventArgs e)
    {
        UserInformation.Value = 2;
    }

private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();

        Loading _loading = new Loading();

        _loading.ShowDialog();

        this.Close();
    }
然后像这样访问它:

public class SystemManager
{
public static void LoadForm(Form _form = null, Form _loadForm = null)
{
   _form.Hide();

   _loadForm = new Form();

   _loadForm.ShowDialog();

   _form.Close();
}
}
public class UserInformation
{
    public static int Value
    {
        get;
        set;
    }
}

public partial class Loading : Form
{
    public Loading()
    {
        InitializeComponent();

        this.timer1.Interval = SystemManager.RandomNumberGenerator(1000, 2000);

        this.timer1.Tick += new EventHandler(this.CheckTimer);
    }

    private void Loading_Load(object sender, EventArgs e)
    {
        this.timer1.Start();
    }

    private void CheckTimer(object sender, EventArgs e)
    {
        uint timeLeft = 1;

        timeLeft--;

        if (timeLeft == 0)
        {
            this.timer1.Stop();

            this.Hide();

            switch (UserInformation.Value)
            {
                case 0:
                AgeConfirmation _ageConfirmation = new AgeConfirmation();

                _ageConfirmation.ShowDialog();
                break;

                case 1:
                MainForm _mainForm = new MainForm();

                _mainForm.ShowDialog();
                break;

                case 2:
                Event _event = new Event();

                _event.ShowDialog();
                break;
            }

            this.Close();
        }
    }
}

private void AgeConfirmation_Load(object sender, EventArgs e)
    {
        UserInformation.Value = 1;
    }

private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();

        Loading _loading = new Loading();

        _loading.ShowDialog();

        this.Close();
    }

private void MainForm_Load(object sender, EventArgs e)
    {
        UserInformation.Value = 2;
    }

private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();

        Loading _loading = new Loading();

        _loading.ShowDialog();

        this.Close();
    }
SystemManager.LoadForm(此为AGE确认)

但它会抛出以下错误:

“System.Windows.Forms.AgeConfirmation”是一个“类型”,但与“变量”一样使用。

我的问题是:只创建一个表单(加载表单),然后访问该加载表单,当时间达到0时,它将访问不同的表单。

非常感谢你的回答


多谢各位

您应该使用
\u ageConfirmation
,它是表单对象,而不是
ageConfirmation
,它是表单类型

i、 e.
SystemManager.LoadForm(此为确认)

更改

_ageConfirmation.ShowDialog();


我自己解决!我创建一个getter和setter int值,并使用switch case,代码如下:

public class SystemManager
{
public static void LoadForm(Form _form = null, Form _loadForm = null)
{
   _form.Hide();

   _loadForm = new Form();

   _loadForm.ShowDialog();

   _form.Close();
}
}
public class UserInformation
{
    public static int Value
    {
        get;
        set;
    }
}

public partial class Loading : Form
{
    public Loading()
    {
        InitializeComponent();

        this.timer1.Interval = SystemManager.RandomNumberGenerator(1000, 2000);

        this.timer1.Tick += new EventHandler(this.CheckTimer);
    }

    private void Loading_Load(object sender, EventArgs e)
    {
        this.timer1.Start();
    }

    private void CheckTimer(object sender, EventArgs e)
    {
        uint timeLeft = 1;

        timeLeft--;

        if (timeLeft == 0)
        {
            this.timer1.Stop();

            this.Hide();

            switch (UserInformation.Value)
            {
                case 0:
                AgeConfirmation _ageConfirmation = new AgeConfirmation();

                _ageConfirmation.ShowDialog();
                break;

                case 1:
                MainForm _mainForm = new MainForm();

                _mainForm.ShowDialog();
                break;

                case 2:
                Event _event = new Event();

                _event.ShowDialog();
                break;
            }

            this.Close();
        }
    }
}

private void AgeConfirmation_Load(object sender, EventArgs e)
    {
        UserInformation.Value = 1;
    }

private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();

        Loading _loading = new Loading();

        _loading.ShowDialog();

        this.Close();
    }

private void MainForm_Load(object sender, EventArgs e)
    {
        UserInformation.Value = 2;
    }

private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();

        Loading _loading = new Loading();

        _loading.ShowDialog();

        this.Close();
    }
程序运行时,
UserInformation.Value
将为0


非常感谢您回答我的问题。

如果(timeLeft==0)
在这段代码中总是正确的。您能解释一下为什么您认为这是对这个问题的回答吗?