按下最小化时程序关闭
本文关键字:程序 最小化 | 更新日期: 2023-09-27 18:28:33
我有两个函数
private void Main_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
{
Hide();
notification.BalloonTipTitle = "Smart Connection";
notification.BalloonTipText = "Smart Connection has been minimized to the taskbar.";
notification.ShowBalloonTip(3000);
}
}
对于我的Form
最小化和
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (connected)
{
if (MessageBox.Show("Are you sure?",
setting.Split(':')[0],
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2) == DialogResult.No)
{
e.Cancel = true;
}
}
}
对于我的Form
关闭事件
但当我按下最小化按钮时,MessageBox
会过来说"你确定吗?"
对于"是"answers"否"按钮,当我按下其中任何一个时,程序都将关闭。
但是,为什么它们是针对两个不同事件的两个不同功能?
我发现为什么this.Hide()
关闭我的猪肉,因为我的飞溅形式
这是我的斜杠
public partial class Splash : DevComponents.DotNetBar.Metro.MetroForm
{
public Splash()
{
InitializeComponent();
}
private void timer_Tick(object sender, EventArgs e)
{
progress.Value += 2;
if (progress.Value == progress.Maximum)
{
this.Hide();
timer.Stop();
Main f = new Main();
f.ShowDialog();
this.Close();
}
}
}
我的Program.cs
是
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool createdNew;
using (var mutex = new System.Threading.Mutex(true, "SmartConnection", out createdNew))
{
if (createdNew)
{
Application.Run(new Splash());
}
else
{
MessageBox.Show("some text");
}
}
}
在上执行"查找所有引用"
private void Main_FormClosing(object sender, FormClosingEventArgs e)
我的猜测是,它不仅仅与FormClose X.有关
编辑:我尝试了你的关闭事件,当我单击"否"时,它不会关闭,所以不确定为什么它仍然关闭。