我参考下面的文章写了一个SplashScreen:
http://www.codeproject.com/csharp/PrettyGoodSplashScreen.asp
为了简化问题,我的主要代码如下:SplashScreen.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace SplashScreen
{
public partial class SplashScreen : Form
{
static SplashScreen ms_frmSplash = null;
static Thread ms_oThread = null; static public void ShowSplashScreen()
{
// Make sure it is only launched once.
if (ms_frmSplash != null)
return;
ms_oThread = new Thread(new ThreadStart(SplashScreen.ShowForm));
ms_oThread.Start();
} static private void ShowForm()
{
ms_frmSplash = new SplashScreen();
Application.Run(ms_frmSplash);
} static public void CloseForm()
{
ms_frmSplash.Close();
}
public SplashScreen()
{
InitializeComponent(); this.ClientSize = this.BackgroundImage.Size;
}
}
}Program.cs:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace SplashScreen
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new SplashScreen());
SplashScreen.ShowSplashScreen();
Thread.Sleep(3000);
SplashScreen.CloseForm(); Form1 form1 = new Form1();
form1.TopMost = true;
form1.ShowDialog(); }
}
}无论怎样设置form1的TopMost属性,都无法将form1显示在最前端,而且似乎不仅仅是TopMost属性的问题,当SplashScreen窗口关闭后根本看不到form1窗口,form1窗口隐藏到了当前窗口(例如VisualStudio开发窗口)的后面,一定要最小化当前的窗口才能看到form1窗口。如果我把Program.cs中显示SplashScreen的三行代码去掉,form1就正常了。请大家帮忙看看问题在哪?
http://www.codeproject.com/csharp/PrettyGoodSplashScreen.asp
为了简化问题,我的主要代码如下:SplashScreen.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace SplashScreen
{
public partial class SplashScreen : Form
{
static SplashScreen ms_frmSplash = null;
static Thread ms_oThread = null; static public void ShowSplashScreen()
{
// Make sure it is only launched once.
if (ms_frmSplash != null)
return;
ms_oThread = new Thread(new ThreadStart(SplashScreen.ShowForm));
ms_oThread.Start();
} static private void ShowForm()
{
ms_frmSplash = new SplashScreen();
Application.Run(ms_frmSplash);
} static public void CloseForm()
{
ms_frmSplash.Close();
}
public SplashScreen()
{
InitializeComponent(); this.ClientSize = this.BackgroundImage.Size;
}
}
}Program.cs:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace SplashScreen
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new SplashScreen());
SplashScreen.ShowSplashScreen();
Thread.Sleep(3000);
SplashScreen.CloseForm(); Form1 form1 = new Form1();
form1.TopMost = true;
form1.ShowDialog(); }
}
}无论怎样设置form1的TopMost属性,都无法将form1显示在最前端,而且似乎不仅仅是TopMost属性的问题,当SplashScreen窗口关闭后根本看不到form1窗口,form1窗口隐藏到了当前窗口(例如VisualStudio开发窗口)的后面,一定要最小化当前的窗口才能看到form1窗口。如果我把Program.cs中显示SplashScreen的三行代码去掉,form1就正常了。请大家帮忙看看问题在哪?
解决方案 »
- 急!!!用正则获取网页中指定的内容!
- 多线程导致程序无响应问题
- DataGridView中下拉选框的问题
- 有关存储的问题?
- 如何才能让ADO和ADO.net的字符串通用?
- 有经验的朋友谈谈Remoting和Soap实际应用问题。
- VS2005的一个问题.
- 用C#.net写在线播放视频........高手帮忙啊!!!急用在线等待!.................
- 为什么连接时候可以直接调用储存过程,而没有事先声明
- 把搜索结果显示在datagrid中,每次查询时,datagrid中的显示数据都会变化,这时它触发的是什么事件?
- reportViewer最简单问题(vs2005 C#)
- 背景图片问题.
http://www.codeproject.com/csharp/PrettyGoodSplashScreen.asp
中copy出来的,原文中需要在SplashScreen中使用进度条等控件,并在主程序中更新这些控件,所以开了一个新的线程。开线程是把程序变复杂了,但我认为并没有引入错误,如果需要更新SplashScreen中的控件,开线程就是必须的。我是为了简化问题,所以在这里没有使用任何控件。由于SplashScreen窗口是在一个独立的线程中运行的,所以Application.Run(ms_frmSplash)是在一个独立的线程中运行的,主线程在调用了SplashScreen.ShowSplashScreen()之后仍然可以继续运行。现在的问题是如何将form1显示到前面来,由于需要使用form1返回的DialogResult(虽然我在这里贴出的代码中没有使用),所以我使用了form1.ShowDialog();希望大家能在VisualStudio中建一个项目,把上面的代码贴进去试试,看看问题到底出在哪里,谢谢了。 :)
using...
namespace SplashScreen
{
public partial class SplashScreen : Form
{
static SplashScreen ms_frmSplash = null; static public void ShowForm()
{
ms_frmSplash = new SplashScreen();
ms_frmSplash.Show();
} static public void CloseForm()
{
ms_frmSplash.Close();
}
public SplashScreen()
{
InitializeComponent(); this.ClientSize = this.BackgroundImage.Size;
}
}
}
Program.cs:
using ...
namespace SplashScreen
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); SplashScreen.ShowForm();
Thread.Sleep(3000);
SplashScreen.CloseForm(); Form1 form1 = new Form1();
form1.ShowDialog();
}
}
}的确,上述代码不使用线程,可以很好的运行,form1的TopMost属性没有任何问题。但是,如果我需要在一个新的线程中启动SplashScreen该如何写呢? :)
如何弹出一个模式窗口来显示进度条
http://blog.csdn.net/knight94/archive/2006/05/27/757351.aspx