Splashscreen - 访问标签和进度条

时间:2015-03-18 07:35:01

标签: c# winforms progress splash

我在使用splashScreen访问ProgressBar和某个Label时遇到了一些问题。我为屏幕制作了一个自己的表格。在我的Form1中,我有以下方法:

    private void sign_Click(object sender, EventArgs e)
    {
        splashScreen splScreen = new splashScreen();
        Thread thrd = new Thread(new ThreadStart(loadingScreenStart));
        thrd.Start();
        splScreen.percentage.Text = "0%";
        var logIn = new LogIn(this);
        logIn.checkUserInput(this);

        thrd.Abort();
    }

      public void loadingScreenStart()
    {
        Application.Run(new splashScreen());
    }

在我的LogIn课程中,我做了:

       public String checkUserInput(object sender)
    {
        splashScreen splScreen = new splashScreen();
        //won't change my Label and PrpgressBar

我知道这可能是因为我创建了一个新的Form实例,所以它是空的,但如何做到这一点呢?我不知道......希望有人可以帮助我。

1 个答案:

答案 0 :(得分:1)

相同的要求我也需要使用相同的对象,但是我有一个限制,我不能使用静态类。为此我创建了一个类的静态对象并使用锁。如果它能解决您的要求,请尝试。

    private static splashScreen m_instance = null;
    private static object m_instanceLock = new object();

    public static splashScreen GetInstance()
    {
        lock (m_instanceLock)
        {
            if (m_instance == null)
            {
                m_instance = new splashScreen();
            }
        }
        return m_instance;
    }

无论何时您想要创建对象或访问已创建的对象,您只需要提供:

SomeClass someobj= SomeClass.GetInstance();
相关问题