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

            string title   = FL.AppErrorDialogTitle;
            string appName = FL.AppName;

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

            AutoScaleDimensions = new SizeF(96, 96);
            AutoScaleMode       = AutoScaleMode.Dpi;
            scaleFactor         = CurrentAutoScaleDimensions.Width / 96;

            BackColor       = SystemColors.Window;
            ControlBox      = false;
            MinimizeBox     = false;
            MaximizeBox     = false;
            Font            = SystemFonts.MessageBoxFont;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            ShowInTaskbar   = false;
            Size            = new Size(Scale(550), Scale(350));
            StartPosition   = FormStartPosition.CenterScreen;
            Text            = title;
            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));
            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(ClientSize.Width, 0);
            introLabel.Padding     = Scale(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     = Scale(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;
            // Always keep the vertical scrollbar width free because the label wouldn't get smaller
            // when the vertical scrollbar appears and then the horizontal scrollbar kicks in as well.
            errorLabel.MaximumSize = new Size(errorPanel.ClientSize.Width - SystemInformation.VerticalScrollBarWidth - 2, 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(ClientSize.Width - Scale(20), 0);
            logLabel.Margin      = Scale(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   = Scale(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                     = Scale(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[] { Scale(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();
                int maxHeight     = Screen.FromControl(this).Bounds.Height;
                int missingHeight = 0;
                int desiredHeight = Height + Scale(300);
                Height = desiredHeight;
                if (Height < desiredHeight)
                {
                    // A window is automatically constrained to the size of its screen, so we can
                    // compare the current size with what we had requested to know how much is
                    // missing for the layout.
                    missingHeight = desiredHeight - Height;
                }
                Top -= Scale(Math.Min(Top - 4, 150));
                if (Top < 0)
                {
                    Top = 0;
                }
                tablePanel.RowStyles[4].Height = Scale(350) - missingHeight;
                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      = Scale(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       = Scale(new Padding(6, 0, 0, 0));
            nextButton.Padding      = Scale(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       = Scale(new Padding(6, 0, 0, 0));
            terminateButton.Padding      = Scale(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       = Scale(new Padding(6, 0, 0, 0));
            continueButton.Padding      = Scale(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);
        }