从另一个类调用 NotifyIcon.ShowBalloonTip()

发布于 2024-09-25 04:51:54 字数 246 浏览 0 评论 0原文

我正在用 C# 开发 Windows 窗体应用程序。我有一个名为 MainWindow 的主窗体和一个名为 notifyIcon 的 NotifyIcon 对象,该对象属于 MainWindow 类。

我使用其他类的notifyIcon的最佳方法是什么?

我知道,如果没有实例,我只能访问类的公共静态成员,但是如果我将 notificationIcon 设置为公共静态,它就会停止在 MainWindow 上工作。

有什么想法吗?

I'm developing a Windows Form application in C#. I have a main form called MainWindow and a NotifyIcon object called notifyIcon that belongs to the MainWindow class.

What is the best way for me to use notifyIcon from other classes?

I know that, without an instance, I can only access public static members of the class, but if I set the notifyIcon as public static, it stops working on MainWindow.

Any ideas?

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

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

发布评论

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

评论(2

走走停停 2024-10-02 04:51:54

如果它是同一应用程序,您可以使用它

Application.OpenForms

来检索打开的表单。

该属性返回一个FormCollection,您可以从那里获取表单实例。 更多信息

如果不是同一个程序集

If it's the same application you can use

Application.OpenForms

to retrieve opened forms.

This property returns a FormCollection, you can get the form instance from there. More info here.

If it's not the same assembly see this.

谜泪 2024-10-02 04:51:54

您可以在表单上公开公共方法。该方法内部可以调用notifyicon上的方法

You can expose a public method on the form. This method can internally call the methods on notifyicon

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