版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1.添加notifyIcon、contextMenuStrip控件到表单,
设置notifyIcon属性
contextMenuStrip属性
编写事件:
this.ShowInTaskbar = false;///使窗体不显示在任务栏
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem)
{
ToolStripMenuItem tsmItem = sender as ToolStripMenuItem;
switch (tsmItem.Text)
{
#region 打开spy++
case "打开spy++":
if (Directory.Exists(Environment.CurrentDirectory + string.Format("\\Tools\\")) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(Environment.CurrentDirectory + string.Format("\\Tools\\"));
}
//IntPtr mainHandle = FindWindow(null, "Microsoft Spy++ - Windows 1");
//if (mainHandle != IntPtr.Zero)
//{
// SetForegroundWindow(mainHandle);
// SendMessage(mainHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0); // 最大化
// SendKeys.SendWait("%{F3}");
//}
//else
//{
// string file = Environment.CurrentDirectory + string.Format("\\Tools\\spyxx.exe");
// if (File.Exists(file))
// {
// System.Diagnostics.Process spyxx = System.Diagnostics.Process.Start(file);
// spyxx.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
// spyxx.WaitForInputIdle(1000);
// if (spyxx.Responding)
// {
// SetForegroundWindow(spyxx.Handle);
// SendMessage(spyxx.Handle, WM_SYSCOMMAND, SC_RESTORE, 0); // 最大化
// SendKeys.SendWait("%{F3}");
// }
// }
//}
break;
#endregion
#region 发送程序到屏幕
case "发送程序到屏幕":
//设置到粘贴板
break;
#endregion
#region 为屏幕指定程序
case "复制为屏幕指定程序":
//设置到粘贴板
break;
#endregion
#region 显示主界面
case "显示主界面":
this.Visible = true;
this.WindowState = FormWindowState.Normal;
break;
#endregion
#region 启动服务
case "启动服务":
if (btnCapture.Text == "启动服务")
{
Start(); btnCapture.Text = "停止服务"; btnCapture.BackColor = SystemColors.Control;
}
break;
#endregion
#region 停止服务
case "停止服务":
if (btnCapture.Text == "停止服务")
{
Stop(); btnCapture.Text = "启动服务"; btnCapture.BackColor = SystemColors.Control;
}
break;
#endregion
#region 退出
case "退出":
this.Close();
break;
#endregion
}
}
#endregion
#endregion
}