public override Size GetPreferredSize(Size proposedSize)
        {
            PropertyModelView propertyModelView = View as PropertyModelView;

            if (propertyModelView != null)
            {
                int height = (propertyModelView.GetProperties().Count +
                              propertyModelView.SectionCount + 2) * 20 +
                             propertyGrid1.GetPreferredSize(proposedSize).Height;

                return(new Size(propertyGrid1.GetPreferredSize(proposedSize).Width, height));
            }
            return(new Size(propertyGrid1.GetPreferredSize(proposedSize).Width,
                            propertyGrid1.GetPreferredSize(proposedSize).Height));
        }
示例#2
0
        private void CreateEditors()
        {
            SuspendLayout();
            PropertyModelView propertyModelView = _registeredViews[0];
            int nonemptyGroups = 0;

            foreach (PropertyDescriptor property in propertyModelView.GetProperties())
            {
                if (property.GetChildProperties().Count > 0)
                {
                    ++nonemptyGroups;
                }
            }

            if (nonemptyGroups < 2 || propertyModelView.SectionCount < 2)
            {
                bool drawBox = false;
                PropertyDescriptorCollection properties    = propertyModelView.GetProperties();
                DialogSectionControl         clientControl =
                    new DialogSectionControl(this, properties, drawBox, this.Title);
                topLevelControlMap[View.Handler.ID] = clientControl;
                this.Controls.Add(clientControl);
                sectionControl = clientControl;
                minHeight      = clientControl.PreferredSize.Height;
                minWidth       = clientControl.PreferredSize.Width;
                topControl     = clientControl;
            }
            else
            {
                TabControl multipleCategoryTabControl = new TabControl()
                {
                    Multiline = multiLine
                };
                if (multiLine)
                {
                    multipleCategoryTabControl.SizeMode = TabSizeMode.FillToRight;
                }
                Controls.Add(multipleCategoryTabControl);
                sectionControl = multipleCategoryTabControl;
                PropertyDescriptorCollection properties = propertyModelView.GetProperties();
                foreach (PropertyDescriptor property in properties)
                {
                    if (property.GetChildProperties().Count == 0)
                    {
                        continue;
                    }
                    string  category = property.Category;
                    string  name     = category.TrimStart('\r');
                    TabPage page     = new TabPage(name);
                    page.Name = name;
                    DialogSectionControl clientControl =
                        new DialogSectionControl(this, property.GetChildProperties(), property, false);
                    page.Controls.Add(clientControl);
                    topLevelControlMap[
                        ((PropertyModelView.OptionItemPropertyDescriptor)
                             ((PropertyModelView.OptionItemPropertyDescriptor)property).Owner).ID] = clientControl;
                    page.Dock = DockStyle.Fill;
                    multipleCategoryTabControl.TabPages.Add(page);
                    minHeight = Math.Max(minHeight, clientControl.Height);
                    minWidth  = Math.Max(minWidth, clientControl.PreferredSize.Width);
                }

                minWidth += 3;
                int tabSize = 0;
                if (multiLine)
                {
                    for (int i = 0; i < multipleCategoryTabControl.TabCount; ++i)
                    {
                        var rect = multipleCategoryTabControl.GetTabRect(i);
                        tabSize = Math.Max(tabSize, rect.Location.Y);
                    }
                }
                else
                {
                    tabSize = multipleCategoryTabControl.ItemSize.Height;
                }
                minHeight += tabSize + multipleCategoryTabControl.Margin.Vertical;

                multipleCategoryTabControl.Width  = minWidth;
                multipleCategoryTabControl.Height = minHeight;
                topControl = multipleCategoryTabControl;
                multipleCategoryTabControl.Dock = DockStyle.Fill;
            }

            ResumeLayout(false);
        }