コード例 #1
0
        public AttributeInspectorForm()
        {
            InitializeComponent();

            /* remove existing tabs and add in our attribute property tabs */
            List<Type> tabsToRemove = new List<Type>();
            foreach (PropertyTab tabToRemove in attributePropertyGrid.PropertyTabs)
                tabsToRemove.Add(tabToRemove.GetType());
            foreach (Type tabToRemove in tabsToRemove)
                attributePropertyGrid.PropertyTabs.RemoveTabType(tabToRemove);
            attributePropertyGrid.PropertyTabs.AddTabType(typeof(GraphPropertyTab), PropertyTabScope.Static);
            attributePropertyGrid.PropertyTabs.AddTabType(typeof(NodePropertyTab), PropertyTabScope.Static);
            attributePropertyGrid.PropertyTabs.AddTabType(typeof(EdgePropertyTab), PropertyTabScope.Static);

            _inspected = null;
            _inspectMainForm = delegate(object sender, EventArgs e)
            {
                /* if the main form has a graph, monitor its changes and show its properties */
                GraphForm graphForm = FormController.Instance.MainForm as GraphForm;
                if (graphForm != null)
                {
                    if (_inspected != null)
                        _inspected.Changed -= _inspectMainForm;
                    _inspected = graphForm;
                    _inspected.Changed += _inspectMainForm;

                    Text = "Attributes of " + graphForm.Text;
                    attributePropertyGrid.SelectedObject = graphForm.Graph;
                }
            };

            /* inspect the graph when the handle has been created */
            /* NOTE: if we set the SelectedObject BEFORE the handle has been created, this damages the property tabs, a Microsoft bug */
            if (attributePropertyGrid.IsHandleCreated)
                _inspectMainForm(this, EventArgs.Empty);
            else
                attributePropertyGrid.HandleCreated += _inspectMainForm;

            /* inspect the graph when the main form changes */
            FormController.Instance.MainFormChanged += _inspectMainForm;
        }