Search code examples
c#.netimageeventsloading

How can i show an image while my application is loading


i have and application windows form .net and my form1 takes a lot of time to appear because in it's event form1_Load does a lot of operation.

My goal is to show an image while the operation are being done.

private void form1_Load(object sender, EventArgs e)
{            
    methode1();
}

While my methode1() is working, my form doesnt show, i want to show an image on the screen while my methode1() is working because while methode1() is working, there is nothing on the screen.


Solution

  • All the visual things in .net is done on form. You can do it by creating an small form which contains an image load it before module1() and after completing module1() close it. Just below..

    private void form1_Load(object sender, EventArgs e)
    {    
            Form f = new Form();
            f.Size = new Size(400, 10);
            f.FormBorderStyle = FormBorderStyle.None;
            f.MinimizeBox = false;
            f.MaximizeBox = false;
            Image im = Image.FromFile(path);
            PictureBox pb = new PictureBox();
            pb.Dock = DockStyle.Fill;
            pb.Image = im;
            pb.Location = new Point(5, 5);
            f.Controls.Add(pb);
            f.Show();        
            methode1();
            f.Close();
    }