Ok so I've got this form with an interface, a tab control, and a
toolstrip. The interface allows users to create custom tab pages and
toolstrip menu's that are then added to a menu of the main form during
start up. These plugins come from external dll's. The problem I'm
having now is that, when I attempt to update my plugin tabpage with
it's associated custom menu item, then main tab control never seems to
get the update. In a step through I can see the Interface "Page"
member for the plugin being updated correctly but when the form
finishes the delegate the actual page you see in the tabcontrol
doesn't seem to get the update. I've recently started trying to get a
delegate to pass down through to the plugin but was having some issues
and wondered if anyone else had any better idea's.

<code>
namespace Foo
{
        public class Foo
        {
                void Main()
                {
                        Application.Run(new MainForm);
                }
        }

        public class MainForm()
        {
                Button btnAddPlugin = new Button();
                ToolStripPanel tspMenus = new TooStripPanel();
                TabControl tabMain = new TabControl();

                void MainForm()
                {
                        init();
                }

                void init()
                {
                        //btnAddPlugin inits....
                        btnAddPlugin += new EventHandler(AddPlugin);
                }

                void AddPlugin(object sender, EventArgs e)
                {
                        foreach(Plugin tmpPlug in FindAvailablePlugins())
                        {
                                //Validation logic
                                tabMain.TabPages.Add(tmPlug.Page);
                                tspMenus.Join(tmpPlug.Menu);
                        }
                }
        }

        public interface Plugin
        {
                string Name { get; }
                ToolStrip Menu { get; }
                TabPage Page { get; }
                void init();
        }
}

namespace Bar
{
        public delegate Reset(object sender, EventArgs e);

        class Bar : Plugin
        {
                private event Reset del_Reset;

                string Name { get; private set; }
                ToolStrip Menu { get; private set; }
                TabPage Page { get; private set; }

                void init()
                {
                        del_Reset += new Reset(ResetTabPage_Click);

                        Menu = new BarMenu(del_Reset);
                        Page = new BarPage();
                }

                void ResetTabPage_Click(object sender, EventArgs e)
                {
                        Page = new BarPage();
                        /*This appears to work on the step through everything 
updates in
memory properly but when the
                        delegate finishes the tabMain control doesn't seem to 
see the
updates*/
                }
        }

        class BarMenu : ToolStrip
        {
                private event Reset del_Reset;
                ToolStripButton reset = new ToolStripButton

                void BarMenu(Reset tmpDel_Reset)
                {
                        del_Reset = tmpDel_Reset;
                        init();
                }

                void init()
                {
                        //reset inits...
                        reset.Click += new EventHandler(reset_Click);

                        this.Items.AddRange(new ToolStripItem[] {reset});
                }

                void reset_Click(object sender, EventArgs e)
                {
                        del_Reset.DynamicInvoke(sender, e);
                }
        }
}
</code>

Reply via email to