[英]how to program the alt+tab close button in a c#.net winforms application
为了最小化到系统托盘,首先从工具箱中在您的表单上添加 NotifyIcon。 然后相应地添加此代码。
private System.Windows.Forms.ContextMenu notifyMenu;
private System.Windows.Forms.MenuItem notifyMenuItemClose;
public static bool close = false;
public ApplicationWindow()
{
InitializeComponent();
}
private void ApplicationWindow_Load(object sender, EventArgs e)
{
this.notifyMenu = new System.Windows.Forms.ContextMenu();
this.notifyMenuItemClose = new System.Windows.Forms.MenuItem();
this.notifyMenu.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.notifyMenuItemClose });
this.notifyMenuItemClose.Index = 0;
this.notifyMenuItemClose.Text = "Exit";
this.notifyMenuItemClose.Click += new System.EventHandler(this.notifyMenuItemClose_Click);
this.notifyAppIcon.ContextMenu = this.notifyMenu;
}
private void notifyMenuItemClose_Click(object sender, EventArgs e)
{
close = true;
this.Close();
}
private void ApplicationWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (close)
{
e.Cancel = false;
}
else
{
WindowState = FormWindowState.Minimized;
e.Cancel = true;
}
}
private void notifyAppIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
{
this.Show();
WindowState = FormWindowState.Normal;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.