コード例 #1
0
        public void AddButtontoDialogBox(CyPhyComponentAuthoringToolGUI CATgut, CATName attr, Type classtype, MethodInfo meth)
        {
            // add the Event Handler to the Button List
            CATName a = (CATName)attr;

            EventHandler handler;

            // create a delegate event handler for the button
            if (classtype.Name == typeof(CyPhyComponentAuthoringInterpreter).Name)
            {
                // local methods don't require a new instance of CATModule
                handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this, meth);
            }
            else
            {
                CATModule newinst = CreateCATModuleLogged(classtype);
                if (newinst == null)
                {
                    return;
                }

                // create a delegate for the dialog button to call to invoke the method
                handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), newinst, meth);
            }

            // Create our list view item
            CatToolListViewItem listViewItem = new CatToolListViewItem(attr, CATgut.ComponentIconList);

            listViewItem.Action += handler;

            CATgut.CatModuleListView.Items.Add(listViewItem);

            // associate the event handler with the button click
            //ev.AddEventHandler(button, handler);

            // Add a second event handler to each button to close the CAT dialog box after executing the first event handler
            //ev.AddEventHandler(button, (EventHandler)((sender, e) => close_dialog_box(sender, e)));
        }
コード例 #2
0
        public void AddButtontoDialogBox(CyPhyComponentAuthoringToolGUI CATgut, CATName attr, Type classtype, MethodInfo meth)
        {
            // add the Event Handler to the Button List
            CATName a = (CATName)attr;

            // setup button properties
            Button button = new Button();
            button.Name = a.NameVal;
            button.Text = a.NameVal;
            button.Anchor = AnchorStyles.Top;

            // set the button size
            button.Width = CAT_BUTTON_WIDTH;
            button.Height = CAT_BUTTON_HEIGHT;

            // make clicking the button an event we can handle
            Type buttonType = typeof(Button);
            EventInfo ev = buttonType.GetEvent("Click");
            Delegate handler = null;

            // create a delegate event handler for the button
            if (classtype.Name == typeof(CyPhyComponentAuthoringInterpreter).Name)
            {
                // local methods don't require a new instance of CATModule
                handler = Delegate.CreateDelegate(ev.EventHandlerType, this, meth);
            }
            else
            {
                // create a new CATModule class instance 
                CATModule newinst = Activator.CreateInstance(classtype) as CATModule;
                if (newinst == null)
                {
                    // problem
                    this.Logger.WriteFailed("Unable to create a new CATModule class instance. CreateInstance call failed.");
                    return;
                }

                // set the current component for use by the new class instance
                newinst.SetCurrentComp(StashCurrentComponent);
                newinst.CurrentProj = StashProject;
                newinst.CurrentObj = StashCurrentObj;

                // create a delegate for the dialog button to call to invoke the method
                handler = Delegate.CreateDelegate(ev.EventHandlerType, newinst, meth);
            }
            // associate the event handler with the button click
            ev.AddEventHandler(button, handler);

            // Add a second event handler to each button to close the CAT dialog box after executing the first event handler
            Delegate closer = Delegate.CreateDelegate(ev.EventHandlerType, this, this.GetType().GetMethod("close_dialog_box"));
            ev.AddEventHandler(button, closer);

            // add another row to the table - each "row" is actually a smaller 2 column table
            TableLayoutPanel new_mini_table = new TableLayoutPanel();
            new_mini_table.AutoSize = true;
            new_mini_table.ColumnCount = 2;
            new_mini_table.RowCount = 1;

            // create the button
            new_mini_table.Controls.Add(button, 0, 0);

            //setup description properties
            Label description = new Label();
            description.Text = a.DescriptionVal;
            description.MinimumSize = new System.Drawing.Size(CAT_DESCRIPTION_WIDTH, CAT_DESCRIPTION_HEIGHT);
            description.Anchor = AnchorStyles.Top;
            description.TextAlign = ContentAlignment.MiddleCenter;
            
            // set the description
            new_mini_table.Controls.Add(description, 1, 0);

            // add the new CAT module to the dialog box
            CATgut.tableLayoutPanel0.Controls.Add(new_mini_table, 1, ++CATgut.tableLayoutPanel0.RowCount);
        }
コード例 #3
0
        public void AddButtontoDialogBox(CyPhyComponentAuthoringToolGUI CATgut, CATName attr, Type classtype, MethodInfo meth)
        {
            // add the Event Handler to the Button List
            CATName a = (CATName)attr;

            // setup button properties
            Button button = new Button();

            button.Name   = a.NameVal;
            button.Text   = a.NameVal;
            button.Anchor = AnchorStyles.Top;

            // set the button size
            button.Width  = CAT_BUTTON_WIDTH;
            button.Height = CAT_BUTTON_HEIGHT;

            // make clicking the button an event we can handle
            Type      buttonType = typeof(Button);
            EventInfo ev         = buttonType.GetEvent("Click");
            Delegate  handler    = null;

            // create a delegate event handler for the button
            if (classtype.Name == typeof(CyPhyComponentAuthoringInterpreter).Name)
            {
                // local methods don't require a new instance of CATModule
                handler = Delegate.CreateDelegate(ev.EventHandlerType, this, meth);
            }
            else
            {
                CATModule newinst = CreateCATModule(classtype);
                if (newinst == null)
                {
                    return;
                }

                // create a delegate for the dialog button to call to invoke the method
                handler = Delegate.CreateDelegate(ev.EventHandlerType, newinst, meth);
            }
            // associate the event handler with the button click
            ev.AddEventHandler(button, handler);

            // Add a second event handler to each button to close the CAT dialog box after executing the first event handler
            ev.AddEventHandler(button, (EventHandler)((sender, e) => close_dialog_box(sender, e)));

            // add another row to the table - each "row" is actually a smaller 2 column table
            TableLayoutPanel new_mini_table = new TableLayoutPanel();

            new_mini_table.AutoSize    = true;
            new_mini_table.ColumnCount = 2;
            new_mini_table.RowCount    = 1;

            // create the button
            new_mini_table.Controls.Add(button, 0, 0);

            //setup description properties
            Label description = new Label();

            description.Text        = a.DescriptionVal;
            description.MinimumSize = new System.Drawing.Size(CAT_DESCRIPTION_WIDTH, CAT_DESCRIPTION_HEIGHT);
            // description.Anchor = AnchorStyles.Top;
            description.TextAlign = ContentAlignment.MiddleCenter;

            // set the description
            new_mini_table.Controls.Add(description, 1, 0);

            // add the new CAT module to the dialog box
            CATgut.tableLayoutPanel0.Controls.Add(new_mini_table, 1, ++CATgut.tableLayoutPanel0.RowCount);
        }