C# 在 load 怎么隐藏窗体
来源:百度知道 编辑:UC知道 时间:2024/05/21 15:43:03
因为我做的这个程序直接与服务器连接如果原来已经连上就直接进入主界面并隐藏登陆界面
load默认的是打开窗体 this.Hide() 执行的是隐藏窗体 在这使用肯定无效`
不要写在Form1_Load()中,这一个是载入时发生的,你要写在初始化代码中。
private void Form1_Activated(object sender, EventArgs e)
{
this.Hide();
}
//窗体激活事件
private void Form1_Activated(object sender, System.EventArgs e)
{
this.Visible=false;
}
1.窗体一加载立刻激活
2.如果真想在load方法里写点什么那就写Form1_Activated(sender,e);
创建一个类继承ApplicationContext:
internal class HideApplicationContext : ApplicationContext
{
private Form hideForm;
public HideApplicationContext(Form mainForm)
{
this.hideForm = mainForm;
}
}
然后在Main()函数中:
HideApplicationContext context = new HideApplicationContext(new StatusBarTest());
Application.Run(context);
为什么要在load中隐藏窗体啊