C#中怎样关闭一个窗口却让他最小化的方法?

2025-03-09 20:59:33
推荐回答(3个)
回答1:

我给你转一个网上的:

添加 NotifyIcon,设定你在托盘的图标

把form 的 showintoolbar 设为 false

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel =true;
this.Hide ();
this.notifyIcon1.Visible =true;
}

private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
if(this.Visible ==true) //根据窗口的显示和隐藏设置Trayico对象的显示
{
this.Hide();
this.notifyIcon1 .Visible =true;
}
else
{
this.Show();
this.notifyIcon1.Visible =false;
}
}

private void ntIcon_DoubleClick(object sender, System.EventArgs e)

{

if (this.WindowState == FormWindowState.Minimized)

{

this.Visible=true;

this.WindowState = FormWindowState.Normal;

this.Activate();

}

else

{

WindowState=FormWindowState.Minimized;

this.Visible=false;

}

}

private void fm_Main_Resize(object sender, System.EventArgs e) {

if (this.WindowState == FormWindowState.Minimized) {

this.Visible = false;

this.notifyIcon1.Icon = this.Icon;

this.notifyIcon1.Text = this.Text;

this.notifyIcon1.Visible = true;

}

}

private void notifyIcon1_Click(object sender, System.EventArgs e) {

this.Visible = true;

this.WindowState = FormWindowState.Normal;

this.notifyIcon1.Visible = false;

}

回答2:

其实就是隐藏,this.names.hide();即可

回答3:

windows+M就行了