2012-05-30 185 views
2

我有和应用程序窗体窗体.net和我的窗体1需要大量时间才能显示,因为在它的事件form1_Load做了很多操作。如何在我的应用程序加载时显示图像

我的目标是在操作完成时显示图像。

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

虽然我methode1()的工作,我的形式犯规表演,我想在屏幕上显示的图像,而我的methode1()的工作,因为在methode1()工作,没有什么在屏幕上。

+1

在C#谷歌的闪屏 –

回答

2

所有.NET中的视觉的东西是在形式完成。您可以通过创建一个包含图像的小表单,在module1()之前加载并在完成module1()关闭之后完成。正下方..

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

使用静态图像创建另一个表单,并在应用程序开始加载之前显示它,然后将其销毁。总是在最上面,没有边界是通常的设置这样的事情。

2

试试这个代码

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

此代码使用微软的Rx到其他很酷的功能

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

中执行在后台线程操作为了这个码工作你需要引用两个nuget软件包:Rx和Rx窗体形式

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

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

相关问题