Beispiel #1
0
        // The PropertyGrid doesn't provide a settable SelectedTab property. Well, it does now.
        public static void SetSelectedTabInPropertyGrid(PropertyGrid propGrid, int selectedTabIndex)
        {
            if ((selectedTabIndex < 0) || (selectedTabIndex >= propGrid.PropertyTabs.Count))
            {
                throw new ArgumentException("Invalid tab index to select: " + selectedTabIndex);
            }

            FieldInfo buttonsField = propGrid.GetType().GetField("viewTabButtons", BindingFlags.NonPublic | BindingFlags.Instance);

            ToolStripButton[] viewTabButtons = (ToolStripButton[])buttonsField.GetValue(propGrid);
            ToolStripButton   viewTabButton  = viewTabButtons[selectedTabIndex];

            propGrid.GetType().InvokeMember("OnViewTabButtonClick", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, propGrid, new object[] { viewTabButton, EventArgs.Empty });
        }
        static public void ResizeDescriptionArea(PropertyGrid grid, int lines)
        {
            try
            {
                var info       = grid.GetType().GetProperty("Controls");
                var collection = (Control.ControlCollection)info.GetValue(grid, null);

                foreach (var control in collection)
                {
                    var type = control.GetType();

                    if ("DocComment" == type.Name)
                    {
                        const BindingFlags Flags = BindingFlags.Instance | BindingFlags.NonPublic;
                        var field = type.BaseType.GetField("userSized", Flags);
                        field.SetValue(control, true);

                        info = type.GetProperty("Lines");
                        info.SetValue(control, lines, null);

                        grid.HelpVisible = true;
                        break;
                    }
                }
            }

            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
Beispiel #3
0
        public static void Save(PropertyGrid control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control", "Control is null.");
            }

            var baseValueName = Helper.GetControlPath(control);

            Write(baseValueName + ".PropertySort", System.Convert.ToInt32(control.PropertySort, CultureInfo.InvariantCulture));

            var fieldGridView  = control.GetType().GetField("gridView", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance);
            var gridViewObject = fieldGridView.GetValue(control);

            if (gridViewObject != null)
            {
                var propertyInternalLabelWidth = gridViewObject.GetType().GetProperty("InternalLabelWidth", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance);
                if (propertyInternalLabelWidth != null)
                {
                    var val = propertyInternalLabelWidth.GetValue(gridViewObject, null);
                    if (val is int)
                    {
                        Write(baseValueName + ".LabelWidth", (int)val);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Восстановление положения разделителя в гриде
        /// </summary>
        private void RestoreGridSplitterPos(PropertyGrid grid, int pos, int height)
        {
            try
            {
                Type      type  = grid.GetType();
                FieldInfo field = type.GetField("gridView",
                                                BindingFlags.NonPublic | BindingFlags.Instance);

                object valGrid  = field.GetValue(grid);
                Type   gridType = valGrid.GetType();
                gridType.InvokeMember("MoveSplitterTo",
                                      BindingFlags.NonPublic | BindingFlags.InvokeMethod
                                      | BindingFlags.Instance,
                                      null,
                                      valGrid, new object[] { pos });

                foreach (Control control in grid.Controls)
                {
                    if (control.GetType().Name == "DocComment")
                    {
                        FieldInfo fieldInfo = control.GetType().BaseType.GetField("userSized",
                                                                                  BindingFlags.Instance |
                                                                                  BindingFlags.NonPublic);
                        fieldInfo.SetValue(control, true);
                        control.Height = height;
                        break;
                    }
                }
            }
            catch
            {
            }
        }
Beispiel #5
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            PropertyInfo info = propertyGrid1.GetType().GetProperty("Controls");

            Control.ControlCollection collection = (Control.ControlCollection)info.GetValue(propertyGrid1, null);

            foreach (object control in collection)
            {
                Type type = control.GetType();
                if ("DocComment" == type.Name)
                {
                    const BindingFlags Flags = BindingFlags.Instance | BindingFlags.NonPublic;
                    FieldInfo          field = type.BaseType.GetField("userSized", Flags);
                    field.SetValue(control, true);

                    info = type.GetProperty("Lines");
                    info.SetValue(control, 5, null);

                    propertyGrid1.HelpVisible = true;
                    break;
                }
            }
        }
Beispiel #6
0
        public static void SetLabelColumnWidth(PropertyGrid grid, int width)
        {
            if (grid == null)
            {
                return;
            }

            FieldInfo fi = grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic);

            if (fi == null)
            {
                return;
            }

            Control view = fi.GetValue(grid) as Control;

            if (view == null)
            {
                return;
            }

            MethodInfo mi = view.GetType().GetMethod("MoveSplitterTo", BindingFlags.Instance | BindingFlags.NonPublic);

            if (mi == null)
            {
                return;
            }
            mi.Invoke(view, new object[] { width });
        }
Beispiel #7
0
        /// <summary>
        /// Сохранение положения разделителя в гриде
        /// </summary>
        private void SaveGridSplitterPos(PropertyGrid grid, out int pos, out int height)
        {
            Type      type  = grid.GetType();
            FieldInfo field = type.GetField("gridView",
                                            BindingFlags.NonPublic | BindingFlags.Instance);

            object valGrid  = field.GetValue(grid);
            Type   gridType = valGrid.GetType();

            pos = (int)gridType.InvokeMember(
                "GetLabelWidth",
                BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
                null,
                valGrid, new object[] { });

            height = 71;
            foreach (Control control in grid.Controls)
            {
                if (control.GetType().Name == "DocComment")
                {
                    height = control.Height;
                    break;
                }
            }
        }
Beispiel #8
0
        public static bool ResizeDescriptionArea(PropertyGrid grid, int nNumLines)
        {
            try
            {
                PropertyInfo pi = grid.GetType().GetProperty("Controls");
                Control.ControlCollection cc = (Control.ControlCollection)pi.GetValue(grid, null);
                foreach (Control c in cc)
                {
                    Type   ct    = c.GetType();
                    string sName = ct.Name;

                    if (sName == "DocComment")
                    {
                        pi = ct.GetProperty("Lines");
                        pi.SetValue(c, nNumLines, null);
                        FieldInfo fi = ct.BaseType.GetField("userSized", BindingFlags.Instance | BindingFlags.NonPublic);
                        fi.SetValue(c, true);
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
    /// <summary>
    /// Moves splitter between two columns
    /// </summary>
    /// <param name="propertyGrid">Source PropertyGrid control</param>
    /// <param name="pos">Splitter position</param>
    /// <example>
    ///     <code>
    ///         propertyGrid1.MoveSplitterTo(Convert.ToInt32(propertyGrid1.Width * 0.8));
    ///         //Column1 width = 80%, Column2 width = 20%
    ///     </code>
    /// </example>
    /// <remarks>
    ///     Contributed by nagits, http://about.me/AlekseyNagovitsyn
    /// </remarks>
    public static void MoveSplitterTo(this PropertyGrid propertyGrid, int pos)
    {
        FieldInfo  fiGridView       = propertyGrid.GetType().GetField("gridView", BindingFlags.NonPublic | BindingFlags.Instance);
        object     oGridView        = fiGridView.GetValue(propertyGrid);
        MethodInfo miMoveSplitterTo = oGridView.GetType().GetMethod("MoveSplitterTo", BindingFlags.NonPublic | BindingFlags.Instance);

        miMoveSplitterTo.Invoke(oGridView, new object[] { pos });
    }
Beispiel #10
0
        void setpgColumnWidth(PropertyGrid grid, int width)
        {
            FieldInfo  fi   = grid?.GetType().GetField("tabViewWorkflow", BindingFlags.Instance | BindingFlags.NonPublic);
            Control    view = fi?.GetValue(grid) as Control;
            MethodInfo mi   = view?.GetType().GetMethod("MoveSplitterTo", BindingFlags.Instance | BindingFlags.NonPublic);

            mi?.Invoke(view, new object[] { width });
        }
Beispiel #11
0
    public static void SetLabelColumnWidth(this PropertyGrid grid, int width)
    {
        FieldInfo  fi   = grid?.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic);
        Control    view = fi?.GetValue(grid) as Control;
        MethodInfo mi   = view?.GetType().GetMethod("MoveSplitterTo", BindingFlags.Instance | BindingFlags.NonPublic);

        mi?.Invoke(view, new object[] { width });
    }
Beispiel #12
0
        //FIXME: why is PropertyEditorCell public but EditorManager isn't?
        static void LoadPropertyEditorAssembly(PropertyGrid propertyGrid, Assembly assembly)
        {
            const BindingFlags bfi = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
            var managerProp        = propertyGrid.GetType().GetProperty("EditorManager", bfi);
            var manager            = managerProp.GetValue(propertyGrid);
            var loadMeth           = manager.GetType().GetMethod("LoadEditor");

            loadMeth.Invoke(manager, new [] { assembly });
        }
Beispiel #13
0
        private void SetPropertyGridColumnWidth()
        {
            Type       propertyGridType = _propertyGridMediaFile.GetType();
            FieldInfo  fieldInfo        = propertyGridType.GetField("gridView", BindingFlags.NonPublic | BindingFlags.Instance);
            object     gridView         = fieldInfo.GetValue(_propertyGridMediaFile);
            Type       gridViewType     = gridView.GetType();
            MethodInfo methodInfo       = gridViewType.GetMethod("MoveSplitterTo", BindingFlags.NonPublic | BindingFlags.Instance);

            methodInfo.Invoke(gridView, new object[] { 100 });
        }
Beispiel #14
0
        public static GridItemCollection GetAllGridEntries(PropertyGrid grid)
        {
            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            object view = grid.GetType().GetField("gridView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(grid);

            return((GridItemCollection)view.GetType().InvokeMember("GetAllGridEntries", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, view, null));
        }
Beispiel #15
0
 private void SoftRefreshPropertyGrid(PropertyGrid propertyGrid)
 {
     if (propertyGrid.GetType().GetField("peMain", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(propertyGrid) is GridItem peMain)
     {
         var refreshMethod = peMain.GetType().GetMethod("Refresh");
         if (refreshMethod != null)
         {
             refreshMethod.Invoke(peMain, null);
             propertyGrid.Invalidate(true);
         }
     }
 }
Beispiel #16
0
 /// <summary>
 /// Changes the description of the item in Property Grid.
 /// </summary>
 /// <param name="propertyGridItemLabel">The property grid item label.</param>
 private void ChangeDescription(string propertyGridItemLabel)
 {
     try
     {
         object oDocComment            = myGrid.GetType().InvokeMember("doccomment", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, myGrid, null);
         Label  oDocCommentDescription = (Label)oDocComment.GetType().InvokeMember("m_labelDesc", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, oDocComment, null);
         oDocCommentDescription.Text = (string)Resources.ResourceManager.GetString("OptionDescription_" + propertyGridItemLabel);
     }
     catch (Exception ex)
     {
         AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Warning, 379, Resources.ProblemWithDescriptionForOption + ex.Message);
     }
 }
Beispiel #17
0
        // https://stackoverflow.com/questions/288893/how-to-prevent-scroll-on-refresh-in-a-propertygrid
        public static void SoftRefreshPropertyGrid(PropertyGrid propertyGrid)
        {
            var peMain = propertyGrid.GetType().GetField("peMain", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(propertyGrid) as System.Windows.Forms.GridItem;

            if (peMain != null)
            {
                var refreshMethod = peMain.GetType().GetMethod("Refresh");
                if (refreshMethod != null)
                {
                    refreshMethod.Invoke(peMain, null);
                    propertyGrid.Invalidate(true);
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Metoda zmieniająca szerokość pierwszej kolumny w kontrolce typu PropertyGrid zgodnie z zadaną szerokością (<paramref name="width"/>)
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="width"></param>
        private void SetPropertyLabelColumnWidth(PropertyGrid grid)
        {
            var width      = 130;
            var memberInfo = grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic);

            if (memberInfo != null)
            {
                var temp          = (Control)memberInfo.GetValue(grid);
                var tempFieldInfo = temp.GetType().GetField("labelWidth", BindingFlags.Instance | BindingFlags.NonPublic);
                if (tempFieldInfo != null)
                {
                    tempFieldInfo.SetValue(temp, width);
                }
                temp.Invalidate();
            }
        }
Beispiel #19
0
        /// <summary>
        /// Creates a new CollectionForm to display the collection editor
        /// </summary>
        /// <remarks>
        /// This methods uses reflection to access non-public fields/properties within the collectionform.
        /// This method can also be used to alter other visual aspects of the form.
        /// </remarks>
        /// <returns>CollectionForm</returns>
        protected override CollectionForm CreateCollectionForm()
        {
            //Get a reference top new collection form
            CollectionEditor.CollectionForm form = base.CreateCollectionForm();

            //Center the form
            form.StartPosition = FormStartPosition.CenterParent;

            //Get the forms type
            Type formType = form.GetType();

            //Get a reference to the private fieldtype propertyBrowser
            //This is the propertgrid inside the collectionform
            FieldInfo fieldInfo = formType.GetField("propertyBrowser", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fieldInfo != null)
            {
                //get a reference to the propertygrid instance located on the form
                PropertyGrid propertyGrid = (PropertyGrid)fieldInfo.GetValue(form);

                if (propertyGrid != null)
                {
                    //Make the tool bar visible
                    propertyGrid.ToolbarVisible = true;

                    //Make the help/description visible
                    propertyGrid.HelpVisible = true;

                    //Get the property grid's type.
                    //Note that this is a vsPropertyGrid located in System.Windows.Forms.Design
                    Type propertyGridType = propertyGrid.GetType();

                    //Get a reference to the non-public property ToolStripRenderer
                    PropertyInfo propertyInfo = propertyGridType.GetProperty("ToolStripRenderer", BindingFlags.NonPublic | BindingFlags.Instance);

                    if (propertyInfo != null)
                    {
                        //Assign a ToolStripProfessionalRenderer with our custom color table
                        propertyInfo.SetValue(propertyGrid, new ToolStripProfessionalRenderer(new CustomColorTable()), null);
                    }
                }
            }

            //Return the form
            return(form);
        }
Beispiel #20
0
        public void SetPropertyGridViewLabelColumnWidth(PropertyGrid grid, int width)
        {
            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            // get the grid view
            Control view = (Control)grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(grid);

            // set label width
            FieldInfo fi = view.GetType().GetField("labelWidth", BindingFlags.Instance | BindingFlags.NonPublic);

            fi.SetValue(view, width);

            // refresh
            view.Invalidate();
        }
Beispiel #21
0
        public static int GetPropertyGridSplitter(PropertyGrid _propertyGrid)
        {
            var realType = _propertyGrid.GetType();

            while (realType != null && realType != typeof(PropertyGrid))
            {
                realType = realType.BaseType;
            }
            var gvf = realType.GetField(@"gridView",
                                        BindingFlags.NonPublic |
                                        BindingFlags.GetField |
                                        BindingFlags.Instance);
            var gv    = gvf.GetValue(_propertyGrid);
            var mtf   = gv.GetType();
            int width = (int)mtf.InvokeMember("GetLabelWidth", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, gv, new object[] { });

            return(width);
        }
Beispiel #22
0
        public static void ResizeDescriptionArea(ref PropertyGrid grid, int nNumLines)
        {
            try
            {
                System.Reflection.PropertyInfo pi = grid.GetType().GetProperty("Controls");
                Control.ControlCollection      cc = (Control.ControlCollection)pi.GetValue(grid, null);

                foreach (Control c in cc)
                {
                    Type   ct    = c.GetType();
                    string sName = ct.Name;

                    if (sName == "DocComment")
                    {
                        pi = ct.GetProperty("Lines");
                        if (pi != null)
                        {
#pragma warning disable 168
                            int i = (int)pi.GetValue(c, null);
#pragma warning restore 168
                            pi.SetValue(c, nNumLines, null);
                        }

                        if (ct.BaseType != null)
                        {
                            System.Reflection.FieldInfo fi = ct.BaseType.GetField("userSized",
                                                                                  System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

                            if (fi != null)
                            {
                                fi.SetValue(c, true);
                            }
                        }
                        break;
                    }
                }
            }
            catch
            {
            }
        }
Beispiel #23
0
        public static void Load(PropertyGrid control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control", "Control is null.");
            }

            var baseValueName = Helper.GetControlPath(control);

            try {
                control.PropertySort = (PropertySort)(Read(baseValueName + ".PropertySort", System.Convert.ToInt32(control.PropertySort, CultureInfo.InvariantCulture)));
            } catch (InvalidEnumArgumentException) { }

            var fieldGridView  = control.GetType().GetField("gridView", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance);
            var gridViewObject = fieldGridView.GetValue(control);

            if (gridViewObject != null)
            {
                var currentlabelWidth          = 0;
                var propertyInternalLabelWidth = gridViewObject.GetType().GetProperty("InternalLabelWidth", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance);
                if (propertyInternalLabelWidth != null)
                {
                    var val = propertyInternalLabelWidth.GetValue(gridViewObject, null);
                    if (val is int)
                    {
                        currentlabelWidth = (int)val;
                    }
                }

                var labelWidth = Read(baseValueName + ".LabelWidth", currentlabelWidth);
                if ((labelWidth > 0) && (labelWidth < control.Width))
                {
                    var methodMoveSplitterToFlags = BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance;
                    var methodMoveSplitterTo      = gridViewObject.GetType().GetMethod("MoveSplitterTo", methodMoveSplitterToFlags);
                    if (methodMoveSplitterTo != null)
                    {
                        methodMoveSplitterTo.Invoke(gridViewObject, methodMoveSplitterToFlags, null, new object[] { labelWidth }, CultureInfo.CurrentCulture);
                    }
                }
            }
        }
Beispiel #24
0
        void propertyGrid1_Paint(object sender, PaintEventArgs e)
        {
            PropertyGrid propertyGrid = (PropertyGrid)sender;

            if (propertyGrid.SelectedObject == null)
            {
                return;
            }

            if (propertyGrid.SelectedObject.GetType().GetInterface(typeof(IPropertyGridCategoryOrder).FullName) == null)
            {
                return;
            }

            IPropertyGridCategoryOrder propertyGridCategoryOrder = (IPropertyGridCategoryOrder)propertyGrid.SelectedObject;
            List <string> propertyGridCategoryNames = propertyGridCategoryOrder.PropertyGridCategoryNames;

            switch (propertyGridCategoryOrder.OrderType)
            {
            case PropertyGridOrderType.Ascending:
                propertyGridCategoryNames = (from tmpItem in propertyGridCategoryNames orderby tmpItem ascending select tmpItem).ToList();
                break;

            case PropertyGridOrderType.Descending:
                propertyGridCategoryNames = (from tmpItem in propertyGridCategoryNames orderby tmpItem descending select tmpItem).ToList();
                break;

            case PropertyGridOrderType.Custom:
                break;
            }

            GridItemCollection currentPropEntries = propertyGrid.GetType().GetField("currentPropEntries", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(propertyGrid1) as GridItemCollection;

            propertyGrid.CollapseAllGridItems();
            var newarray = currentPropEntries.Cast <GridItem>().OrderBy((t) => propertyGridCategoryNames.IndexOf(t.Label)).ToArray();

            currentPropEntries.GetType().GetField("entries", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(currentPropEntries, newarray);
            propertyGrid.ExpandAllGridItems();
            propertyGrid.PropertySort = (PropertySort)propertyGrid.Tag;
            propertyGrid.Paint       -= new PaintEventHandler(propertyGrid1_Paint);
        }
Beispiel #25
0
        private void ToLog()
        {
            // Create a new property grid and expand it, to access all items
            // This beats implementing the property logic to fetch all of item.
            PropertyGrid grid = new PropertyGrid();

            grid.SelectedObject = Properties.SelectedObject;
            grid.ExpandAllGridItems();
            object view = grid.GetType().GetField("gridView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(grid);

            // Log each category recursively
            GridItemCollection items = (GridItemCollection)view.GetType().InvokeMember("GetAllGridEntries", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, view, null);

            foreach (GridItem item in items)
            {
                if (item.GridItemType == GridItemType.Category)
                {
                    LogItem(item, string.Empty);
                }
            }
        }
Beispiel #26
0
        public static void Load(PropertyGrid control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control", "Control is null.");
            }

            string baseValueName = Helper.GetControlPath(control);

            try {
                control.PropertySort = (System.Windows.Forms.PropertySort)(Helper.Read(baseValueName + ".PropertySort", System.Convert.ToInt32(control.PropertySort, System.Globalization.CultureInfo.InvariantCulture)));
            } catch (System.ComponentModel.InvalidEnumArgumentException) { }

            System.Reflection.FieldInfo fieldGridView = control.GetType().GetField("gridView", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            object gridViewObject = fieldGridView.GetValue(control);

            if (gridViewObject != null)
            {
                int currentlabelWidth = 0;
                System.Reflection.PropertyInfo propertyInternalLabelWidth = gridViewObject.GetType().GetProperty("InternalLabelWidth", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                if (propertyInternalLabelWidth != null)
                {
                    object val = propertyInternalLabelWidth.GetValue(gridViewObject, null);
                    if (val is int)
                    {
                        currentlabelWidth = (int)val;
                    }
                }
                int labelWidth = Helper.Read(baseValueName + ".LabelWidth", currentlabelWidth);
                if ((labelWidth > 0) && (labelWidth < control.Width))
                {
                    System.Reflection.BindingFlags methodMoveSplitterToFlags = System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
                    System.Reflection.MethodInfo   methodMoveSplitterTo      = gridViewObject.GetType().GetMethod("MoveSplitterTo", methodMoveSplitterToFlags);
                    if (methodMoveSplitterTo != null)
                    {
                        methodMoveSplitterTo.Invoke(gridViewObject, methodMoveSplitterToFlags, null, new object[] { labelWidth }, System.Globalization.CultureInfo.CurrentCulture);
                    }
                }
            }
        }
Beispiel #27
0
        public static void SetPropertyGridSplitter(PropertyGrid _propertyGrid, int _width)
        {
            var realType = _propertyGrid.GetType();

            while (realType != null && realType != typeof(PropertyGrid))
            {
                realType = realType.BaseType;
            }

            var gvf = realType.GetField(@"gridView",
                                        BindingFlags.NonPublic |
                                        BindingFlags.GetField |
                                        BindingFlags.Instance);
            var gv = gvf.GetValue(_propertyGrid);

            var mtf = gv.GetType().GetMethod(@"MoveSplitterTo",
                                             BindingFlags.NonPublic |
                                             BindingFlags.InvokeMethod |
                                             BindingFlags.Instance);

            mtf.Invoke(gv, new object[] { _width });
        }
Beispiel #28
0
        protected override CollectionForm CreateCollectionForm()
        {
            CollectionEditor.CollectionForm form = base.CreateCollectionForm();
            form.StartPosition = FormStartPosition.CenterParent;
            Type      formType  = form.GetType();
            FieldInfo fieldInfo = formType.GetField("propertyBrowser", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fieldInfo != null)
            {
                PropertyGrid propertyGrid = (PropertyGrid)fieldInfo.GetValue(form);
                if (propertyGrid != null)
                {
                    propertyGrid.ToolbarVisible = true;
                    propertyGrid.HelpVisible    = true;
                    Type         propertyGridType = propertyGrid.GetType();
                    PropertyInfo propertyInfo     = propertyGridType.GetProperty("ToolStripRenderer", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (propertyInfo != null)
                    {
                        propertyInfo.SetValue(propertyGrid, new ToolStripSystemRenderer(), null);
                    }
                }
            }
            return(form);
        }
        public void OnSelect(object sender, EventArgs e)
        {
            _propGrid.SelectedObjectsChanged -= OnSelect;

            if (_collectionType == typeof(ValueProperty))
            {
                var selectedObject = (ValueProperty)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new ValuePropertyBag(selectedObject), null);
                    _parentValProp = selectedObject.Name;
                }
            }
            else if (_collectionType == typeof(ChildProperty))
            {
                var selectedObject = (ChildProperty)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new ChildPropertyBag(selectedObject), null);
                    _parentValProp = selectedObject.Name;
                }
            }
            else if (_collectionType == typeof(UnitOfWorkProperty))
            {
                var selectedObject = (UnitOfWorkProperty)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new UnitOfWorkPropertyBag(selectedObject), null);
                }
            }
            else if (_collectionType == typeof(Criteria))
            {
                var selectedObject = (Criteria)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new CriteriaBag(selectedObject), null);
                }
            }
            else if (_collectionType == typeof(CriteriaProperty))
            {
                var selectedObject = (CriteriaProperty)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new CriteriaPropertyBag(selectedObject), null);
                }
            }
            else if (_collectionType == typeof(ConvertValueProperty))
            {
                var selectedObject = (ConvertValueProperty)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new ConvertValuePropertyBag(selectedObject), null);
                    _parentValProp = selectedObject.Name;
                }
            }
            else if (_collectionType == typeof(UpdateValueProperty))
            {
                var selectedObject = (UpdateValueProperty)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new UpdateValuePropertyBag(selectedObject), null);
                }
            }
            else if (_collectionType == typeof(BusinessRule))
            {
                var selectedObject = (BusinessRule)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    if (!string.IsNullOrEmpty(ParentValProp))
                    {
                        selectedObject.IsPropertyRule = true;
                        selectedObject.Parent         = _parentValProp;
                    }
                    else
                    {
                        selectedObject.IsPropertyRule = false;
                        selectedObject.Parent         = string.Empty;
                    }

                    propertyInfo.SetValue(_propGrid, new BusinessRuleBag(selectedObject), null);

                    var ruleCount      = 0;
                    var baseCount      = 0;
                    var heightIncrease = 0;
                    var rules          = ((BusinessRuleBag)_propGrid.SelectedObject).SelectedObject;
                    foreach (var businessRule in rules)
                    {
                        ruleCount = businessRule.RuleProperties.Count;
                        if (ruleCount > 0)
                        {
                            heightIncrease = 16 + (ruleCount * 16);
                        }

                        baseCount = businessRule.BaseRuleProperties.Count;
                        if (baseCount > 0)
                        {
                            heightIncrease += 16 + (baseCount * 16);
                        }

                        heightIncrease += 16 * businessRule.NumberGenericParameters;

                        if (ruleCount == 0 && baseCount == 0)
                        {
                            if (_form.Size.Height != 330)
                            {
                                _form.Size = new Size(_form.Size.Width, 330);
                            }
                        }
                        else
                        {
                            if (_form.Size.Height != 306 + heightIncrease)
                            {
                                _form.Size = new Size(_form.Size.Width, 306 + heightIncrease);
                            }
                        }
                    }
                }
            }
            else if (_collectionType == typeof(BusinessRuleConstructor))
            {
                var selectedObject = (BusinessRuleConstructor)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    //selectedObject.Parent = _parentValProp;
                    propertyInfo.SetValue(_propGrid, new BusinessRuleConstructorBag(selectedObject), null);

                    var parameterCount = 0;
                    var genericCount   = 0;
                    var heightIncrease = 0;
                    var constructors   = ((BusinessRuleConstructorBag)_propGrid.SelectedObject).SelectedObject;
                    foreach (var constructor in constructors)
                    {
                        parameterCount = constructor.ConstructorParameters.Count;
                        heightIncrease = parameterCount * 16;

                        foreach (var parameter in constructor.ConstructorParameters)
                        {
                            if (parameter.IsGenericType)
                            {
                                genericCount++;
                            }
                        }
                        if (genericCount > 0)
                        {
                            heightIncrease += 16 + (genericCount * 16);
                        }

                        if (parameterCount == 0 && genericCount == 0)
                        {
                            if (_form.Size.Height != 330)
                            {
                                _form.Size = new Size(_form.Size.Width, 330);
                            }
                        }
                        else
                        {
                            if (_form.Size.Height != 274 + heightIncrease)
                            {
                                _form.Size = new Size(_form.Size.Width, 274 + heightIncrease);
                            }
                        }
                    }
                }
            }
            else if (_collectionType == typeof(DbProvider))
            {
                var selectedObject = (DbProvider)_propGrid.SelectedObject;
                //Get the property grid's type.
                //This is a vsPropertyGrid located in System.Windows.Forms.Design
                var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
                if (selectedObject != null)
                {
                    propertyInfo.SetValue(_propGrid, new DbProviderPropertyBag(selectedObject), null);
                }
            }

            /*else if (_collectionType == typeof(BusinessRuleProperty))
             * {
             *  var selectedObject = (BusinessRuleProperty)_propGrid.SelectedObject;
             *  //Get the property grid's type.
             *  //This is a vsPropertyGrid located in System.Windows.Forms.Design
             *  var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
             *  if (selectedObject != null)
             *      propertyInfo.SetValue(_propGrid, new BusinessRulePropertyBag(selectedObject), null);
             * }
             * else if (_collectionType == typeof(BusinessRuleParameter))
             * {
             *  var selectedObject = (BusinessRuleParameter)_propGrid.SelectedObject;
             *  //Get the property grid's type.
             *  //This is a vsPropertyGrid located in System.Windows.Forms.Design
             *  var propertyInfo = _propGrid.GetType().GetProperty("SelectedObject", BindingFlags.Public | BindingFlags.Instance);
             *  if (selectedObject != null)
             *      propertyInfo.SetValue(_propGrid, new BusinessRuleParameterBag(selectedObject), null);
             * }*/

            _propGrid.Layout += pgEditor_Layout;

            _propGrid.SelectedObjectsChanged += OnSelect;
        }
Beispiel #30
0
        public static GridItemCollection GetAllGridEntries(PropertyGrid grid)
        {
            object view = grid.GetType().GetField("gridView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(grid);

            return((GridItemCollection)view.GetType().InvokeMember("GetAllGridEntries", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, view, null));
        }