单击按钮时让应用程序最小化到系统托盘吗?

发布于 2024-08-01 19:10:15 字数 99 浏览 7 评论 0原文

在 WindowsXP/Vista 中如何让我的应用程序最小化到系统托盘?

我还在寻找一种当鼠标悬停在图标上时自动显示消息的方法。 弹出的气球中可以有两条线吗?

How can I have my application minimize itself to the system tray in WindowsXP/Vista?

I'm also looking for a way to have a message display itself when the mouse is hovered on the icon. Is it possible to have two lines in the pop up balloon?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雄赳赳气昂昂 2024-08-08 19:10:15

我认为您的意思是最小化到系统托盘,因为您已经讨论过图标和消息气球?

以下代码将设置一个托盘图标:

private void SetUpTrayIcon()
{
    notifyIcon = new System.Windows.Forms.NotifyIcon();
    notifyIcon.BalloonTipText = "Ballon minimize text";
    notifyIcon.BalloonTipTitle = "Ballon minimize title";
    notifyIcon.Text = "Icon hover text";
    notifyIcon.Icon = new  System.Drawing.Icon(
               System.Reflection.Assembly.GetExecutingAssembly()
                   .GetManifestResourceStream("MyIcon.ico"));
    notifyIcon.Click += new EventHandler(HandlerToMaximiseOnClick);
}

要在托盘中显示图标(例如,您可能希望在窗口状态更改事件上执行此操作,请执行以下操作:

if (notifyIcon != null)
{
    notifyIcon.Visible = true;
    notifyIcon.ShowBalloonTip(2000);
}

要在要使用的鼠标悬停时显示气球与上面相同的代码可能在图标的 mousemove 中。

注意:如果您想在不同点更改消息,则气球显示的消息将遵循换行符,例如可以将 Environment.NewLine 添加到其中。

I assume you mean minimize to the System tray because you have talked about icons and message ballons?

The following code will set up a tray icon:

private void SetUpTrayIcon()
{
    notifyIcon = new System.Windows.Forms.NotifyIcon();
    notifyIcon.BalloonTipText = "Ballon minimize text";
    notifyIcon.BalloonTipTitle = "Ballon minimize title";
    notifyIcon.Text = "Icon hover text";
    notifyIcon.Icon = new  System.Drawing.Icon(
               System.Reflection.Assembly.GetExecutingAssembly()
                   .GetManifestResourceStream("MyIcon.ico"));
    notifyIcon.Click += new EventHandler(HandlerToMaximiseOnClick);
}

To show the icon in the tray (you may want to do this on the window state change event for example, do something like the following:

if (notifyIcon != null)
{
    notifyIcon.Visible = true;
    notifyIcon.ShowBalloonTip(2000);
}

To display a ballon on mouse hover you want to use the same code as above possibly in the mousemove for the icon.

Note: ShowBalloonTip is overloaded if you want to change the message at different points. The message the balloon displays will respect newlines eg Environment.NewLine can be added to it.

南风几经秋 2024-08-08 19:10:15

尝试

最小化

this.WindowState = FormWindowState.Minimized;

以最小化到托盘请参阅此

什么最小化 C# WinForms 应用程序托盘的正确方法?

再见

try

to minimize

this.WindowState = FormWindowState.Minimized;

to minimize to tray see this

What's the proper way to minimize to tray a C# WinForms app?

Bye

两个我 2024-08-08 19:10:15

弹出气球将显示表单标题栏(即表单的 .Text 属性)中显示的所有内容。 我不知道有什么方法可以使它成为多行(如果有办法,它肯定会很复杂,而且可能不值得麻烦)。

这个较早的问题给出了基本问题的一些答案。 您的工具箱包含一个名为 NotifyIcon 的控件 - 使用它可以在系统托盘中放置一个图标。

The popup balloon will display whatever is shown in the form's title bar (which is the form's .Text property). I don't know of any way to make it multi-lined (if there is a way, it's sure to be complicated and probably not worth the trouble).

This earlier question gives some answers to the basic question. Your toolbox contains a control called NotifyIcon - use this to place an icon in the system tray.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文