2

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.

Raktim Biswas
  • 4,011
  • 5
  • 27
  • 32
pharaon450
  • 493
  • 3
  • 9
  • 21

5 Answers5

2

Create another form, just for loading, with a static image, and display it before your application starts to load, and destroy it afterwards. Always on top, and with no border is the usual setup for such things.

Matzi
  • 13,770
  • 4
  • 33
  • 50
2

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();
}
Md Kamruzzaman Sarker
  • 2,387
  • 3
  • 22
  • 38
2

Try this code

using System.Reactive.Linq;

    private void RealForm_Load(object sender, EventArgs e)
    {
        var g = new Splash();

        // place in this delegate the call to your time consuming operation
        var timeConsumingOperation = Observable.Start(() => Thread.Sleep(5000));
        timeConsumingOperation.ObserveOn(this).Subscribe(x =>
        {
            g.Close();
            this.Visible = true;
        });

        this.Visible = false;
        g.ShowDialog();
    }

This code uses Microsoft Rx to execute operations in background threads among other cool features

http://msdn.microsoft.com/en-us/data/gg577609.aspx

In order for this code to work you need to reference two nuget packages: Rx and Rx windows forms

https://nuget.org/packages/Rx-Main/1.0.11226

https://nuget.org/packages/Rx-WinForms/1.0.11226

Jupaol
  • 21,107
  • 8
  • 68
  • 100
0

(splash screen c# -- google it)

Here's what I just found: http://msdn.microsoft.com/en-us/library/aa446493.aspx

Denis
  • 11,796
  • 16
  • 88
  • 150
0

How about using the built in SplashScreen class?

http://msdn.microsoft.com/en-us/library/system.windows.splashscreen.aspx

embedded.kyle
  • 10,976
  • 5
  • 37
  • 56