请教:
private void SoftwareRegister_Load(object sender, EventArgs e)
{
LoginForm logForm = new LoginForm();
logForm.Show();
}
我现在需要只显示LoginForm 窗体而不显示SoftwareRegister窗体,请各位赐教!
private void SoftwareRegister_Load(object sender, EventArgs e)
{
LoginForm logForm = new LoginForm();
logForm.Show();
}
我现在需要只显示LoginForm 窗体而不显示SoftwareRegister窗体,请各位赐教!
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoginForm());
}
}修改Program.cs文件里的Main方法
创建windows application,然后粘贴如下代码替换Program.cs中所有内容。F5可以看到效果。只是例子。看懂后融合到你项目中。
using System;
using System.Threading;
using System.Windows.Forms;namespace CSharpWin02
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new DemoMainform());
} public class DemoMainform : Form
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.Text = "Mainform";
//休眠模拟消耗时间
SplashForm sf = null;
bool form_inited = false;
new Thread((ThreadStart)delegate
{
sf = new SplashForm();
sf.HandleCreated += (EventHandler)delegate { form_inited = true; };
sf.Show();
sf.BringToFront();
Application.Run(sf);
}).Start();
while (sf == null || !form_inited) ;//do nothing until splash form ready
sf.Invoke((EventHandler)delegate { sf.UpdateState(LoadingState.LoadingResource); });
Thread.Sleep(1000);
sf.Invoke((EventHandler)delegate { sf.UpdateState(LoadingState.LoadingPlugIn); });
Thread.Sleep(1000);
sf.Invoke((EventHandler)delegate { sf.UpdateState(LoadingState.LoadingTools); });
Thread.Sleep(1000);
sf.Invoke((EventHandler)delegate { sf.UpdateState(LoadingState.LoadingFonts); });
Thread.Sleep(1000);
sf.Invoke((EventHandler)delegate { sf.UpdateState(LoadingState.LoadingComplete); });
Thread.Sleep(1000);
sf.Invoke((EventHandler)delegate { sf.Close(); });
}
} //加载状态
public enum LoadingState
{
LoadingResource,
LoadingPlugIn,
LoadingTools,
LoadingFonts,
LoadingComplete
} public class SplashForm:Form
{
public void UpdateState(LoadingState state)
{
lt.Text = state.ToString() + "...";
}
Label lt = new Label();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.Text = "Loading splash form";
this.Controls.Add(lt);
lt.AutoSize = false;
lt.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
lt.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
lt.Left = 0;
lt.Top = 0;
lt.Width = this.Width;
lt.Height=this.Height;
lt.Text = "starting...";
}
}
}
}