如果在构造函数中加载东西,它将使用progressBar进行映像?

时间:2013-12-31 18:17:46

标签: c# winforms

我在构造函数中有这段代码:

InitializeComponent();

            textBox3_text_valid = 0;
            label8.Visible = false;
            label8.Visible = false;
            Logger.exist();
            dt1 = DateTime.Now;
            label1.Text = dt1.ToLongTimeString();
            temperature_label = new Label();
            textMode_label = new Label();
            this.Controls.Add(textMode_label);
            this.Controls.Add(temperature_label);

            temperature_label.Location = new Point(260, 200);
            temperature_label.Height = 250;
            temperature_label.Width = 500;
            temperature_label.ForeColor = Color.Red;
            temperature_label.Font = new Font("Arial", 35, FontStyle.Bold);

            textMode_label.Location = new Point(350, 200);
            textMode_label.Height = 250;
            textMode_label.Width = 500;
            textMode_label.ForeColor = Color.Blue;
            textMode_label.Font = new Font("Arial", 35, FontStyle.Bold);
            textMode_label.Text = " - הטמפרטורה כעת";

            path_log = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log";
            fullPath = path_log + log_file_name;

            timer = new Timer();
            timer.Interval = 100;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
            textBox3.Text = Options_DB.Get_textBox3_time();
            computer = new Computer();
            computer.Open();
            computer.GPUEnabled = true;

问题是computer.Open();大约需要3-5秒。 computer变量是OpenHardwareMonitor-LIB.dll的计算机类的一部分

computer.Open会导致Open添加CPU硬件设备。

我认为有一种方法可以让它更快地运行,所以我怎样才能在屏幕上显示一些图像,progressBar会移动,直到构造函数中的所有内容都出现?

我认为它叫做:SplashForm。

1 个答案:

答案 0 :(得分:1)

是的 - 它被称为启动画面。关于如何在WinForms中执行此操作有很多问题/答案。这是一对,但如果您搜索“splash form”或“splash screen”以及winforms和InitializeComponent,您会发现更多:

Is it possible to create a splash screen before InitializeComponent is called on Form Load of Winforms application?

Updating a Splash Screen with Loading Progress in a VB.Net WinForms Application

<强> ADDITION

这个看起来更好解释:

Creating a Splash Screen in .NET with a progress bar