使用系统托盘 [英] working with system tray

查看:42
本文介绍了使用系统托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的基于窗口的项目创建了一个安装文件.它工作正常.我的要求是当我最小化窗口时,它应该出现在系统托盘中而不是任务栏中.帮我谢谢你

i create a setup file for my window based project. it is working fine. my requirement is when i minimize the window it should come in system tray not in task bar. help me thank u

推荐答案

  1. 首先,打开一个现有的 C# Windows 窗体(或创建一个新窗体).
  2. 打开 Visual Studio 工具箱.
  3. 将 NotifyIcon 控件拖到表单上.默认情况下,该控件将命名为 notifyIcon1 并放置在表单下方,因为它在表单本身上没有可视化表示.
  4. 将 NotifyIcon 控件的 Text 属性设置为您希望在用户将鼠标悬停在应用程序图标上时显示的名称.例如,该值可以是KillerApp 1.0".
  5. 将控件的 Icon 属性设置为您希望在系统托盘中显示的图标.

  1. To get started, open an existing C# Windows form (or create a new one).
  2. Open the Visual Studio Toolbox.
  3. Drag a NotifyIcon control onto the form. The control will named notifyIcon1 by default and placed below the form because it has no visual representation on the form itself.
  4. Set the NotifyIcon control's Text property to the name you want to appear when the user pauses the mouse over the application's icon. For example, this value could be "KillerApp 1.0".
  5. Set the control's Icon property to the icon that you want to appear in the System Tray.

  Tip: If you have a BMP file that you want to convert to an icon file, I highly recommend the QTam Bitmap to Icon 3.5 application.

  • 为表单的 Resize 事件添加一个事件处理程序,当它最小化时将隐藏应用程序.这样,它就不会出现在任务栏上.

  • Add an event handler for the form's Resize event that will hide the application when it's minimized. That way, it won't appear on the task bar.

    private void Form1_Resize(object sender, System.EventArgs e){if (FormWindowState.Minimized == WindowState)隐藏();}

    private void Form1_Resize(object sender, System.EventArgs e) { if (FormWindowState.Minimized == WindowState) Hide(); }

    为 NotifyIcon.DoubleClick 事件添加一个事件处理程序并将其编码如下,以便在双击图标时恢复应用程序.

    Add an event handler for the NotifyIcon.DoubleClick event and code it as follows so that the application will be restored when the icon is double-clicked.

    private void notifyIcon1_DoubleClick(object sender,System.EventArgs e){展示();WindowState = FormWindowState.Normal;}

    private void notifyIcon1_DoubleClick(object sender, System.EventArgs e) { Show(); WindowState = FormWindowState.Normal; }

    这篇关于使用系统托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆