Search code examples
c#notifyicon

Calling NotifyIcon.ShowBalloonTip() from another class


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?


Solution

  • 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.