How can i show an image while my application is loading

梦想与她 提交于 2019-12-06 13:14:17

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();
}

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.

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

(splash screen c# -- google it)

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

How about using the built in SplashScreen class?

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!