示例#1
0
文件: Hacks.cs 项目: smarinel/ags-web
        // 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 });
        }
示例#2
0
        public static void Save(System.Windows.Forms.PropertyGrid control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control", "Control is null.");
            }

            string baseValueName = Helper.GetControlPath(control);

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

            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)
            {
                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)
                    {
                        Helper.Write(baseValueName + ".LabelWidth", (int)val);
                    }
                }
            }
        }
示例#3
0
        private static bool ResizePropertyGridDescriptionArea(PropertyGrid propertyGrid, int lines)
        {
            try
            {
                PropertyInfo propertyInfo = propertyGrid.GetType().GetProperty("Controls");
                Control.ControlCollection controlCollection = (Control.ControlCollection)propertyInfo.GetValue(propertyGrid, null);

                foreach (Control control in controlCollection)
                {
                    Type type = control.GetType();
                    string typeName = type.Name;

                    if (typeName == "DocComment")
                    {
                        propertyInfo = type.GetProperty("Lines");
                        propertyInfo.SetValue(control, lines, null);

                        FieldInfo fieldInfo = type.BaseType.GetField("userSized", BindingFlags.Instance | BindingFlags.NonPublic);
                        fieldInfo.SetValue(control, true);
                    }
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
示例#4
0
        /// <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>
        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 });
        }
示例#5
0
        /// <summary>
        /// Resize the columns of a PropertyGrid.  From http://stackoverflow.com/questions/12447156/14475276#14475276
        /// </summary>
        public static void SetLabelColumnWidth(this System.Windows.Forms.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 });
            view?.Invalidate();
        }
示例#6
0
文件: Form1.cs 项目: Corey-M/Misc
        public static void SetLabelColumnWidth(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();
        }
示例#7
0
        private 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);
            }
        }
示例#8
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);
 }
示例#9
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);
                    }
                }
            }
        }
示例#10
0
文件: FormMain.cs 项目: serialbus/NGK
        //----------------------------------------------------------------------------
        /// <summary>
        /// Метод возвращат ширину первой колонки PropertyGrid
        /// </summary>
        /// <param name="control">PropertyGrid</param>
        /// <returns>Ширина первой колонки</returns>
        private int GetSplitterPropertyGrid(PropertyGrid control)
        {
            Type type = control.GetType();
            FieldInfo field = type.GetField("gridView",
                BindingFlags.NonPublic | BindingFlags.Instance);

            object valGrid = field.GetValue(control);
            Type gridType = valGrid.GetType();
            int width = (int)gridType.InvokeMember("GetLabelWidth",
                BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
                null, valGrid, new object[] { });

            //MessageBox.Show(width.ToString());
            
            return width;
        }
示例#11
0
文件: FormMain.cs 项目: serialbus/NGK
        //----------------------------------------------------------------------------
        /// <summary>
        /// Метод изменяет ширину колонок в контроле PropertyGrid
        /// </summary>
        /// <param name="control">PropertyGrid</param>
        /// <param name="width">Ширина первой колнки</param>
        private void SetSplitterPropertyGrid(PropertyGrid control, int width)
        {
            Type type  = control.GetType();
            
            FieldInfo field = type.GetField("gridView",
                BindingFlags.NonPublic | BindingFlags.Instance);
            
            object valGrid = field.GetValue(control);
            
            Type gridType = valGrid.GetType();

            gridType.InvokeMember("MoveSplitterTo",
                BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance,
                null,
                valGrid,
                new object[] {width});

            return;
        }
        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 });
        }
示例#13
0
        private AppErrorDialog()
        {
            if (!appErrorInitialized)
            {
                Application.EnableVisualStyles();
                appErrorInitialized = true;
            }

            string title = FL.AppErrorDialogTitle;
            string appName = FL.AppName;
            if (!string.IsNullOrEmpty(appName))
            {
                title = appName + " – " + title;
            }

            this.BackColor = SystemColors.Window;
            this.ControlBox = false;
            this.MinimizeBox = false;
            this.MaximizeBox = false;
            this.Font = SystemFonts.MessageBoxFont;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.ShowInTaskbar = false;
            this.Size = new Size(550, 300);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Text = title;
            this.TopMost = true;

            tablePanel = new TableLayoutPanel();
            tablePanel.Dock = DockStyle.Fill;
            tablePanel.RowCount = 6;
            tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            tablePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            tablePanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 0));
            tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            tablePanel.ColumnCount = 1;
            tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
            this.Controls.Add(tablePanel);

            introLabel = new Label();
            introLabel.BackColor = Color.FromArgb(221, 74, 59);
            introLabel.ForeColor = Color.White;
            introLabel.Dock = DockStyle.Fill;
            introLabel.AutoSize = true;
            introLabel.Font = new Font(
                SystemFonts.MessageBoxFont.FontFamily,
                SystemFonts.MessageBoxFont.SizeInPoints * 1.3f,
                SystemFonts.MessageBoxFont.Style);
            introLabel.MaximumSize = new Size(this.ClientSize.Width, 0);
            introLabel.Padding = new Padding(6, 4, 7, 6);
            introLabel.Margin = new Padding();
            introLabel.UseCompatibleTextRendering = false;
            introLabel.UseMnemonic = false;
            tablePanel.Controls.Add(introLabel);
            tablePanel.SetRow(introLabel, 0);
            tablePanel.SetColumn(introLabel, 0);

            errorPanel = new Panel();
            errorPanel.AutoScroll = true;
            errorPanel.Dock = DockStyle.Fill;
            errorPanel.Margin = new Padding(7, 8, 10, 6);
            errorPanel.Padding = new Padding();
            tablePanel.Controls.Add(errorPanel);
            tablePanel.SetRow(errorPanel, 1);
            tablePanel.SetColumn(errorPanel, 0);

            errorLabel = new Label();
            errorLabel.AutoSize = true;
            errorLabel.MaximumSize = new Size(this.ClientSize.Width - 20, 0);
            errorLabel.Padding = new Padding();
            errorLabel.Margin = new Padding();
            errorLabel.UseCompatibleTextRendering = false;
            errorLabel.UseMnemonic = false;
            errorPanel.Controls.Add(errorLabel);

            logLabel = new LinkLabel();
            logLabel.AutoSize = true;
            logLabel.MaximumSize = new Size(this.ClientSize.Width - 20, 0);
            logLabel.Margin = new Padding(8, 6, 10, 0);
            logLabel.Padding = new Padding();
            if (FL.LogFileBasePath != null)
            {
                logLabel.Text = string.Format(FL.AppErrorDialogLogPath, FL.LogFileBasePath.Replace("\\", "\\\u200B") + "*.fl");
                string dir = Path.GetDirectoryName(FL.LogFileBasePath).Replace("\\", "\\\u200B");
                logLabel.LinkArea = new LinkArea(FL.AppErrorDialogLogPath.IndexOf("{0}", StringComparison.Ordinal), dir.Length);
                logLabel.LinkClicked += (s, e) =>
                {
                    Process.Start(Path.GetDirectoryName(FL.LogFileBasePath));
                };
            }
            else
            {
                logLabel.Text = FL.AppErrorDialogNoLog;
                logLabel.LinkArea = new LinkArea(0, 0);
            }
            logLabel.UseCompatibleTextRendering = false;
            logLabel.UseMnemonic = false;
            tablePanel.Controls.Add(logLabel);
            tablePanel.SetRow(logLabel, 2);
            tablePanel.SetColumn(logLabel, 0);

            detailsLabel = new LinkLabel();
            detailsLabel.AutoSize = true;
            detailsLabel.Margin = new Padding(7, 6, 10, 10);
            detailsLabel.Padding = new Padding();
            detailsLabel.TabIndex = 11;
            detailsLabel.Text = FL.AppErrorDialogDetails;
            detailsLabel.UseCompatibleTextRendering = false;
            detailsLabel.Visible = CanShowDetails;
            tablePanel.Controls.Add(detailsLabel);
            tablePanel.SetRow(detailsLabel, 3);
            tablePanel.SetColumn(detailsLabel, 0);

            var attr = new TypeConverterAttribute(typeof(ExpandableObjectConverter));
            TypeDescriptor.AddAttributes(typeof(Exception), attr);
            grid = new PropertyGrid();
            grid.Dock = DockStyle.Fill;
            grid.Margin = new Padding(10, 10, 10, 10);
            grid.ToolbarVisible = false;
            grid.HelpVisible = false;
            grid.PropertySort = PropertySort.Alphabetical;
            grid.UseCompatibleTextRendering = false;
            grid.Visible = false;
            tablePanel.Controls.Add(grid);
            tablePanel.SetRow(grid, 4);
            tablePanel.SetColumn(grid, 0);

            bool isGridColumnResized = false;
            grid.Resize += (s, e) =>
            {
                if (!isGridColumnResized)
                {
                    isGridColumnResized = true;
                    // Source: http://stackoverflow.com/a/14475276/143684
                    FieldInfo fi = grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (fi != null)
                    {
                        Control view = fi.GetValue(grid) as Control;
                        if (view != null)
                        {
                            MethodInfo mi = view.GetType().GetMethod("MoveSplitterTo", BindingFlags.Instance | BindingFlags.NonPublic);
                            if (mi != null)
                            {
                                mi.Invoke(view, new object[] { 170 });
                            }
                            mi = view.GetType().GetMethod("set_GrayTextColor", BindingFlags.Instance | BindingFlags.NonPublic);
                            if (mi != null)
                            {
                                mi.Invoke(view, new object[] { Color.Black });
                            }
                        }
                    }
                }
            };

            detailsLabel.LinkClicked += (s, e) =>
            {
                detailsLabel.Hide();
                this.Height += 300;
                this.Top -= Math.Min(this.Top - 4, 150);
                tablePanel.RowStyles[4].Height = 350;
                grid.Visible = true;
            };

            buttonsPanel = new TableLayoutPanel();
            buttonsPanel.AutoSize = true;
            buttonsPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            buttonsPanel.BackColor = SystemColors.Control;
            buttonsPanel.Dock = DockStyle.Fill;
            buttonsPanel.Margin = new Padding();
            buttonsPanel.Padding = new Padding(10, 10, 10, 10);
            buttonsPanel.ColumnCount = 4;
            buttonsPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
            buttonsPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            buttonsPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            buttonsPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            tablePanel.Controls.Add(buttonsPanel);
            tablePanel.SetRow(buttonsPanel, 5);
            tablePanel.SetColumn(buttonsPanel, 0);

            sendCheckBox = new CheckBox();
            sendCheckBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
            sendCheckBox.AutoSize = true;
            sendCheckBox.Enabled = FL.CanSubmitLog;
            if (sendCheckBox.Enabled)
            {
                sendCheckBox.Checked = true;
            }
            sendCheckBox.FlatStyle = FlatStyle.System;
            sendCheckBox.Margin = new Padding();
            sendCheckBox.Padding = new Padding();
            sendCheckBox.Text = FL.AppErrorDialogSendLogs;
            sendCheckBox.UseCompatibleTextRendering = false;
            buttonsPanel.Controls.Add(sendCheckBox);
            buttonsPanel.SetRow(sendCheckBox, 0);
            buttonsPanel.SetColumn(sendCheckBox, 0);

            nextButton = new Button();
            nextButton.AutoSize = true;
            nextButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            nextButton.FlatStyle = FlatStyle.System;
            nextButton.Margin = new Padding(6, 0, 0, 0);
            nextButton.Padding = new Padding(2, 1, 2, 1);
            nextButton.Text = FL.AppErrorDialogNext;
            nextButton.UseCompatibleTextRendering = false;
            nextButton.UseVisualStyleBackColor = true;
            nextButton.Visible = false;
            nextButton.Click += (s, e) =>
            {
                ShowNextError();
            };
            buttonsPanel.Controls.Add(nextButton);
            buttonsPanel.SetRow(nextButton, 0);
            buttonsPanel.SetColumn(nextButton, 1);

            terminateButton = new Button();
            terminateButton.AutoSize = true;
            terminateButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            terminateButton.FlatStyle = FlatStyle.System;
            terminateButton.Margin = new Padding(6, 0, 0, 0);
            terminateButton.Padding = new Padding(2, 1, 2, 1);
            terminateButton.Text = FL.AppErrorDialogTerminate;
            terminateButton.UseCompatibleTextRendering = false;
            terminateButton.UseVisualStyleBackColor = true;
            terminateButton.Click += (s, e) =>
            {
                StartSubmitTool();
                Close();
                FL.Shutdown();
                Environment.Exit(1);
            };
            buttonsPanel.Controls.Add(terminateButton);
            buttonsPanel.SetRow(terminateButton, 0);
            buttonsPanel.SetColumn(terminateButton, 2);

            continueButton = new Button();
            continueButton.AutoSize = true;
            continueButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            continueButton.FlatStyle = FlatStyle.System;
            continueButton.Margin = new Padding(6, 0, 0, 0);
            continueButton.Padding = new Padding(2, 1, 2, 1);
            continueButton.Text = FL.AppErrorDialogContinue;
            continueButton.UseCompatibleTextRendering = false;
            continueButton.UseVisualStyleBackColor = true;
            continueButton.Click += (s, e) =>
            {
                StartSubmitTool();
                Close();
            };
            buttonsPanel.Controls.Add(continueButton);
            buttonsPanel.SetRow(continueButton, 0);
            buttonsPanel.SetColumn(continueButton, 3);
        }