Closing a form and calling main form's function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fonix232
    New Member
    • Feb 2010
    • 3

    Closing a form and calling main form's function

    Hey it's me again :)
    I will have some more noobish questions today, so prepare yourselves!

    So here you go:

    In my app when I close a form, I want a menu update script to be ran, because on the other form the user can modify some folders what are present in the menu bar too.

    But I can't do that until I change my

    public void loadPlugins()

    into

    public static void loadPlugins()

    .

    But if I do, some of my commands become invalid.

    Here is the code:

    Code:
    public void loadPlugins()
            {
                DirectoryInfo pluginDir = new DirectoryInfo(Application.StartupPath + "//plugins//");
                DirectoryInfo[] plugins = pluginDir.GetDirectories();
                if (plugins.Length == 0)
                {
    
                    ToolStripItem noAddon = pluginsToolStripMenuItem.DropDownItems.Add("[NO ADDONS]");
                    noAddon.Enabled = false;
                }
                else
                {
    
                    foreach (DirectoryInfo plugin in plugins)
                    {
                        pluginsToolStripMenuItem.DropDownItems.Add(plugin.ToString());
    
                    }
    
                }
            }
    Also the other form's onclose event:

    Code:
    private void PluginManager_FormClosing(object sender, FormClosingEventArgs e)
            {
                MainWindow.loadPlugins();
            }
    How could I make this PluginManager form run a function of MainWindow without modifying it's loadPlugins() function?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    In your main form, attach an event handler to the close event of your other form.
    In that handler, you should be able to call your loadPlugins() function

    Comment

    Working...