Удалите объект формы C # и отобразите новые объекты, когда индикатор выполнения завершится и изменит фоновое изображение - PullRequest
0 голосов
/ 10 июня 2018

Я создаю программу, которая после истечения срока выполнения индикатора меняет фоновое изображение, уничтожает текущие объекты формы (например, индикатор выполнения) и отображает новые объекты формы.Объяснение кода высоко ценится.Я использую Visual Studio 2017. Вот как выглядит код.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Form_Application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value < 100)
            {
                this.progressBar1.Increment(1);
            }

            else {
                timer1.Stop();
                Image myImage = new Bitmap(@"C:\Users\user\source\repos\Form Application\Form Application\res\img1.png");
                this.BackgroundImage = myImage;

            }
        }
    }
}

1 Ответ

0 голосов
/ 10 июня 2018
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Form_Application
{
    public partial class Form1 : Form
    {
        //create new form object
        Form1 f = null;
        //This is the constructor of the form
        public Form1()
        {
            //intializecomponent is used to construct the design of a form
            InitializeComponent();
            //ser form1 object to this
            f=this;
            //it the method to start the timer
            this.timer1.Start();
        }
        //this is the event handler which is called when time of the timer is increased
        private void timer1_Tick(object sender, EventArgs e)
        {
            //check if progress bar value is less than 100
            if (progressBar1.Value < 100)
            {
                //increase the value of progress bar by 1
                this.progressBar1.Increment(1);
            }

            else {
                //stop the timer when progress bar value is 100
                timer1.Stop();
                //get the image from the path
                Image myImage = new Bitmap(@"C:\Users\user\source\repos\Form Application\Form Application\res\img1.png");
                //set the image to the forms background here this represents the object of the form
                this.BackgroundImage = myImage;
                //create new form
                Form1 formobj = new Form1();
                //show new form
                formobj.show();
                //close current form
                f.close();
            }
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...