[英]ProcessCmdKey after closing application
I have this function for the ProcessCmdKey
that will run some buttons if I will press Ctrl + A , or Ctrl + N , or Ctrl + S . 我具有用于
ProcessCmdKey
此功能,如果我按Ctrl + A或Ctrl + N或Ctrl + S会运行一些按钮。
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.N))
{
button4_Click(this, null);
return true;
}
if (keyData == (Keys.Control | Keys.A))
{
button3_Click(this, null);
return true;
}
if (keyData == (Keys.Control | Keys.S))
{
label10_Click(this, null);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
I have a question, can it be done that after closing the application (not shutdown app), using Form_Closing
to put the app in System Icons
using notifyIcon
, if you will press Ctrl + A (for example), will run the button? 我有一个问题,在关闭应用程序(不是关机应用程序)之后,使用
Form_Closing
通过notifyIcon
将应用程序放入“ System Icons
中,如果您要按Ctrl + A (例如),会运行按钮吗?
Right now it doesn't work, but can I do this? 现在它不起作用,但是我可以这样做吗?
To set the tray icon see this guide . 要设置托盘图标,请参阅本指南 。
You can set the icon of your project via Project Properties > Application > Icon . 您可以通过项目属性>应用程序>图标来设置项目的图标 。
You can hide the window from the task bar like this: 您可以从任务栏隐藏窗口,如下所示:
this.ShowInTaskbar = false;
This code will stop a form from closing and just hide it (unless windows is shutting down). 此代码将阻止表单关闭并仅将其隐藏(除非关闭了窗口)。
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (e.CloseReason == CloseReason.WindowsShutDown)
{
return;
}
e.Cancel = true;
this.WindowState = FormWindowState.Minimized
}
This code will give you the tray icon and re-show the form when double clicked. 此代码将为您提供任务栏图标,并在双击时重新显示该表单。
public MyForm()
{
InitializeComponent();
NotifyIcon trayIcon = new NotifyIcon()
{
Icon = new Icon(@"C:\Temp\MyIcon.ico"),
BalloonTipText = "Open Me!",
Visible = true
};
trayIcon.DoubleClick += new EventHandler(trayIcon_DoubleClick);
}
public void trayIcon_DoubleClick(object sender, EventArgs e)
{
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Normal;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.