C#以application.run打开的窗体怎么隐藏
//启动主窗体System.Windows.Forms.Application.Run(newfrmMain());...
//启动主窗体 System.Windows.Forms.Application.Run(new frmMain());
展开
1个回答
展开全部
//做一个有参构造函数的窗口
public partial class Form1 : Form
{
bool State;//窗口状态
public Form1(bool a)
{
State = a;
InitializeComponent();
}
protected override void OnShown(EventArgs e)///重写onshown事件
{
if (State)
{
this.ShowInTaskbar = true;
this.WindowState = System.Windows.Forms.FormWindowState.Normal;
base.OnShown(e);
}
else
{
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;//最小化 启动
this.ShowInTaskbar = false;//不在任务栏显示图标
this.Hide();//隐藏窗口
}
}
}
调用的时候用:
System.Windows.Forms.Application.Run(new form1(ture)); //显示主窗口;
System.Windows.Forms.Application.Run(new form1(false));//隐藏主窗口;
public partial class Form1 : Form
{
bool State;//窗口状态
public Form1(bool a)
{
State = a;
InitializeComponent();
}
protected override void OnShown(EventArgs e)///重写onshown事件
{
if (State)
{
this.ShowInTaskbar = true;
this.WindowState = System.Windows.Forms.FormWindowState.Normal;
base.OnShown(e);
}
else
{
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;//最小化 启动
this.ShowInTaskbar = false;//不在任务栏显示图标
this.Hide();//隐藏窗口
}
}
}
调用的时候用:
System.Windows.Forms.Application.Run(new form1(ture)); //显示主窗口;
System.Windows.Forms.Application.Run(new form1(false));//隐藏主窗口;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询