BDe*_*per 19 c# splash-screen winforms
我仍然有启动画面的问题.我不想使用该属性SC.TopMost=true
.
现在我的应用场景如下:
在progeram.cs中:
[STAThread]
static void Main()
{
new SplashScreen(_tempAL);// where _tempAL is an arrayList
Application.Run(new Form1(_tempAL));
}
Run Code Online (Sandbox Code Playgroud)
在SplashScreen类中:
public SplashScreen(ArrayList _Data)
{
DisplaySplash()
}
private void DisplaySplash()
{
this.Show();
this.TopMost = true;
this.CenterToScreen();
this.SetTopLevel(true);
_allServerNarrators = new string[10];
for (int i = 0; i < _allServerNarrators.Length; i++)
_allServerNarrators[i] = null;
GetFromServer();
this.Hide();
_serverData = new ArrayList();
_thisData.Add(_allServerNarrators);
_thisData.Add(_serverNarrators);
}
private void GetFromServer()
{
_serverNarrators = new ArrayList();
string _file = "Suras.serverNar";
if (!Directory.Exists("c:\\ASGAQuraan"))
Directory.CreateDirectory("c:\\ASGAQuraan");
while (counter < 4 && _serverFiles == null)
{
if (Download("c:\\ASGAQuraan", _ftpServerIP, _file))
{
StreamReader _strReader = new StreamReader
("c:\\ASGAQuraan\\"+_file,System.Text.Encoding.Default);
string _line = _strReader.ReadLine();
string _word;
while (true)
{
while (_line != null)
{
_word = _line.Substring(0, _line.IndexOf("*"));
int _narId = Convert.ToInt32(_word);
_line = _line.Substring(2);
int k = 0;
_serverNarratorNode = new ArrayList();
while (true)
{
int ind = _line.IndexOf("*");
if (ind > 0 && ind < _line.Length)
{
string str = _line.Substring(0, (ind));
if (k == 0)
{
_allServerNarrators[_narId] = str;
_serverNarratorNode.Add(str);
}
else
{
_serverNarratorNode.Add(str);
}
_line = _line.Substring(ind + 1);
k++;
}
else
{
_line = null;
break;
}
}
_serverNarrators.Add(_serverNarratorNode);
_serverFiles = "added";
}
_line = _strReader.ReadLine();
if (_line == null)
{
break;
}
}
}
else
counter++;
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的是启动画面类中的某些东西,它一直等到线程结束.
有关详细信息,请告诉我需要告诉您的内容.
Han*_*ant 82
同样的问题,同样的答案:
.NET框架具有出色的内置支持初始屏幕.启动一个新的WF项目Project + Add Reference,选择Microsoft.VisualBasic.添加一个新表单,称之为frmSplash.打开Project.cs并使其如下所示:
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
namespace WindowsFormsApplication1 {
static class Program {
[STAThread]
static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new MyApp().Run(args);
}
}
class MyApp : WindowsFormsApplicationBase {
protected override void OnCreateSplashScreen() {
this.SplashScreen = new frmSplash();
}
protected override void OnCreateMainForm() {
// Do your time consuming stuff here...
//...
System.Threading.Thread.Sleep(3000);
// Then create the main form, the splash screen will close automatically
this.MainForm = new Form1();
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 2
跨两个线程进行跟踪有点令人困惑,但我会尝试说一下......
我在这里不完全理解您的设计,但如果问题是当您启动第二个应用程序时,启动屏幕表单会变成白色......这很可能是由于启动屏幕正忙于执行 GetFromServer 中的所有代码()。太忙了,以至于没有时间重新粉刷自己。
为了解决这个问题,我建议您使用BackGroundWorker 组件来执行 GetFromServer 方法。这将在单独的线程中运行该方法,并让表单的线程自由地重新绘制自身。