GetPreferredSize() public method

public GetPreferredSize ( Size proposedSize ) : Size
proposedSize System.Drawing.Size
return System.Drawing.Size
Esempio n. 1
0
        private void lbReports_SelectedIndexChanged(object sender, EventArgs e)
        {
            panelReportParameters.Controls.Clear();
            if (lbReports.SelectedItem != null)
            {
                Reports.ReportEntry entry = lbReports.SelectedItem as Reports.ReportEntry;
                entry.DefaultsHandler(entry.ReportParameters);

                panelReportParameters.Visible = false;
                Label description = new Label();
                if (entry.ReportParameters != null)
                {
                    panelReportParameters.Controls.Add(entry.ReportParameters);
                }
                panelReportParameters.Controls.Add(description);
                description.Text = entry.Description;
                description.Dock = DockStyle.Top;
                description.Padding = new Padding(0, 0, 0, 6);
                //description.AutoSize = true;
                description.Size = description.GetPreferredSize(description.Size);
                panelReportParameters.Visible = true;
                btnRunReport.Enabled = true;
            }
            else
            {
                btnRunReport.Enabled = false;
            }
        }
Esempio n. 2
0
        private void MenuFileViewPluginLoadErrors_Click(object sender, EventArgs e)
        {
            IList<Triple<Assembly, Type, Exception>> allErrors = AppWorkspace.GetEffectLoadErrors();
            IList<Triple<Assembly, Type, Exception>> errors = RemoveDuplicates(allErrors);

            using (Form errorsDialog = new Form())
            {
                errorsDialog.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuFileViewPluginLoadErrorsIcon.png").Reference);
                errorsDialog.Text = PdnResources.GetString("Effects.PluginLoadErrorsDialog.Text");

                Label messageLabel = new Label();
                messageLabel.Name = "messageLabel";
                messageLabel.Text = PdnResources.GetString("Effects.PluginLoadErrorsDialog.Message.Text");

                TextBox errorsBox = new TextBox();
                errorsBox.Font = new Font(FontFamily.GenericMonospace, errorsBox.Font.Size);
                errorsBox.ReadOnly = true;
                errorsBox.Multiline = true;
                errorsBox.ScrollBars = ScrollBars.Vertical;

                StringBuilder allErrorsText = new StringBuilder();
                string headerTextFormat = PdnResources.GetString("EffectErrorMessage.HeaderFormat");

                for (int i = 0; i < errors.Count; ++i)
                {
                    Assembly assembly = errors[i].First;
                    Type type = errors[i].Second;
                    Exception exception = errors[i].Third;

                    string headerText = string.Format(headerTextFormat, i + 1, errors.Count);
                    string errorText = AppWorkspace.GetLocalizedEffectErrorMessage(assembly, type, exception);

                    allErrorsText.Append(headerText);
                    allErrorsText.Append(Environment.NewLine);
                    allErrorsText.Append(errorText);

                    if (i != errors.Count - 1)
                    {
                        allErrorsText.Append(Environment.NewLine);
                    }
                }

                errorsBox.Text = allErrorsText.ToString();

                errorsDialog.Layout +=
                    delegate(object sender2, LayoutEventArgs e2)
                    {
                        int hMargin = UI.ScaleWidth(8);
                        int vMargin = UI.ScaleHeight(8);
                        int insetWidth = errorsDialog.ClientSize.Width - (hMargin * 2);

                        messageLabel.Location = new Point(hMargin, vMargin);
                        messageLabel.Width = insetWidth;
                        messageLabel.Size = messageLabel.GetPreferredSize(new Size(messageLabel.Width, 1));

                        errorsBox.Location = new Point(hMargin, messageLabel.Bottom + vMargin);
                        errorsBox.Width = insetWidth;
                        errorsBox.Height = errorsDialog.ClientSize.Height - vMargin - errorsBox.Top;
                    };

                errorsDialog.StartPosition = FormStartPosition.CenterParent;
                errorsDialog.ShowInTaskbar = false;
                errorsDialog.MinimizeBox = false;
                errorsDialog.Width *= 2;
                errorsDialog.Size = UI.ScaleSize(errorsDialog.Size);
                errorsDialog.Controls.Add(messageLabel);
                errorsDialog.Controls.Add(errorsBox);

                errorsDialog.ShowDialog(AppWorkspace);
            }
        }
    private bool AddLabelsLeftToRight() {
      var curLoc = new Point(3, 0);
      int idx = 0;

      foreach (var bc in breadcrumbs) {
        Label label;

        if (bc == breadcrumbs.Last.Value) {
          label = new Label { Location = curLoc, AutoSize = true, Font = font, Text = bc.Item1 };
        } else {
          label = new LinkLabel { Location = curLoc, AutoSize = true, Font = font, Text = bc.Item1, Tag = bc };
          ((LinkLabel)label).LinkClicked += label_LinkClicked;
        }

        labels.Add(label);
        label.Size = label.GetPreferredSize(Size.Empty);
        curLoc.X += label.Size.Width;

        if (++idx < breadcrumbs.Count) {
          var separator = new Label { Location = curLoc, AutoSize = true, Font = font, Text = Separator };
          labels.Add(separator);
          separator.Size = separator.GetPreferredSize(Size.Empty);
          curLoc.X += separator.Size.Width;
        }
      }

      double width = Width;
      if (ViewsLabelVisible)
        width -= viewsLabel.Width + viewsLabel.Margin.Left + viewsLabel.Margin.Right;
      bool success = curLoc.X <= width;

      if (success)
        Controls.AddRange(labels.ToArray());

      return success;
    }
Esempio n. 4
0
        /// <summary>
        /// Repairs the installation of Paint.NET by replacing any files that have gone missing.
        /// This method should only be called after it has been determined that the files are missing,
        /// and not as a way to determine which files are missing.
        /// This is used, for instance, if the resource files, such as PaintDotNet.Strings.3.resources,
        /// cannot be found. This is actually a top support issue, and by automatically repairing
        /// this problem we save a lot of people a lot of trouble.
        /// </summary>
        /// <param name="missingFiles">
        /// Friendly names for the files that are missing. These will not be used as part of the
        /// repair process but rather as part of any UI presented to the user, or in an exception that 
        /// will be thrown in the case of an error.
        /// </param>
        /// <returns>
        /// true if everything was successful, false if the user cancelled or does not have administrator
        /// privilege (and cannot elevate). An exception is thrown for errors.
        /// </returns>
        /// <remarks>
        /// Note to implementors: This may be implemented as a no-op. Just return true in this case.
        /// </remarks>
        public static bool ReplaceMissingFiles(string[] missingFiles)
        {
            // Generate a friendly, comma separated list of the missing file names
            StringBuilder missingFilesSB = new StringBuilder();

            for (int i = 0; i < missingFiles.Length; ++i)
            {
                missingFilesSB.Append(missingFiles[i]);

                if (i != missingFiles.Length - 1)
                {
                    missingFilesSB.Append(", ");
                }
            }

            try
            {
                // If they are not an admin and have no possibility of elevating, such as for a standard User
                // in XP, then give them an error. Unfortunately we do not know if we can even load text
                // resources at this point, and so must provide an English-only error message.
                if (!Security.IsAdministrator && !Security.CanElevateToAdministrator)
                {
                    MessageBox.Show(
                        null,
                        "Paint.NET has detected that some important installation files are missing. Repairing " +
                        "this requires administrator privilege. Please run the 'PdnRepair.exe' program in the installation " +
                        "directory after logging in with a user that has administrator privilege." + Environment.NewLine +
                        Environment.NewLine +
                        "The missing files are: " + missingFilesSB.ToString(),
                        "Paint.NET",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    return false;
                }

                const int hMargin = 8;
                const int vMargin = 8;
                Form form = new Form();
                form.Text = "Paint.NET";
                form.ClientSize = new Size(400, 10);
                form.StartPosition = FormStartPosition.CenterScreen;

                Label infoLabel = new Label();
                form.Controls.Add(infoLabel);
                infoLabel.Text =
                    "Paint.NET has detected that some important installation files are missing. If you click " +
                    "the Repair button it will attempt to repair this and then continue loading." + Environment.NewLine +
                    Environment.NewLine +
                    "The missing files are: " + missingFilesSB.ToString();

            #if DEBUG
                infoLabel.Text += Environment.NewLine +
                    "Since this is a DEBUG build, you should probably add /skipRepairAttempt to the command-line.";
            #endif

                infoLabel.Location = new Point(hMargin, vMargin);
                infoLabel.Width = form.ClientSize.Width - hMargin * 2;
                infoLabel.Height = infoLabel.GetPreferredSize(new Size(infoLabel.Width, 1)).Height;

                Button repairButton = new Button();
                form.Controls.Add(repairButton);
                repairButton.Text = "&Repair";

                Exception exception = null;

                repairButton.Click +=
                    delegate(object sender, EventArgs e)
                    {
                        form.DialogResult = DialogResult.Yes;
                        repairButton.Enabled = false;

                        try
                        {
                            Shell.Execute(form, "PdnRepair.exe", "/noPause", false, ExecuteWaitType.WaitForExit);
                        }

                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                    };

                repairButton.AutoSize = true;
                repairButton.PerformLayout();
                repairButton.Width += 20;
                repairButton.Location = new Point((form.ClientSize.Width - repairButton.Width) / 2, infoLabel.Bottom + vMargin * 2);
                repairButton.FlatStyle = FlatStyle.System;
                UI.EnableShield(repairButton, true);

                form.FormBorderStyle = FormBorderStyle.FixedDialog;
                form.MinimizeBox = false;
                form.MaximizeBox = false;
                form.ShowInTaskbar = true;
                form.Icon = null;
                form.ClientSize = new Size(form.ClientRectangle.Width, repairButton.Bottom + vMargin);

                DialogResult result = form.ShowDialog(null);
                form.Dispose();
                form = null;

                if (result == DialogResult.Yes)
                {
                    return true;
                }
                else if (exception == null)
                {
                    return false;
                }
                else
                {
                    throw new Exception("Error while attempting to repair", exception);
                }
            }

            catch (Exception ex)
            {
                throw new Exception("Could not repair installation after it was determined that the following files are missing: " +
                    missingFilesSB.ToString(), ex);
            }
        }
Esempio n. 5
0
        private void LayoutProcessesInfo()
        {
            int x = this.labelAccount.Location.X;
            const int progressDx = 20;
            int y = labelDomainExample.Location.Y + labelDomainExample.Size.Height + 6;
            Size preferredSize;
            int maxLineDx = this.Size.Width - 2 * x;
            foreach (var test in Tests)
            {
                var l = new Label();
                l.ForeColor = System.Drawing.Color.Black;
                l.AutoSize = true;
                l.Location = new System.Drawing.Point(x, y);
                l.Text = test.DisplayName;
                preferredSize = l.GetPreferredSize(new Size(maxLineDx, 13));
                l.Size = preferredSize;
                l.Show();
                test.Label = l;
                this.Controls.Add(l);
                int dy = preferredSize.Height;
                int dx = preferredSize.Width;

                var pi = new ProgressIndicator();
                pi.Location = new Point(x + dx + 4, y-3);
                pi.Size = new Size(progressDx, dy);
                test.ProgressIndicator = pi;
                this.Controls.Add(pi);
                pi.Start();

                y += (dy + 6);
            }
            FinishedCountLabel = new Label();
            FinishedCountLabel.Visible = true;
            FinishedCountLabel.Location = new Point(x, y);
            FinishedCountLabel.Text = String.Format("Finished 0 out {0} tests.", Tests.Count);
            FinishedCountLabel.Location = new Point(x, y);
            //preferredSize = FinishedCountLabel.GetPreferredSize(new Size(maxLineDx, 13));
            //FinishedCountLabel.Size = preferredSize;
            FinishedCountLabel.AutoSize = true;
            this.Controls.Add(FinishedCountLabel);

            SeeResultsLabel = new LinkLabel();
            SeeResultsLabel.Visible = false;
            SeeResultsLabel.Location = new Point(x, y);
            SeeResultsLabel.Text = "See results";
            preferredSize = SeeResultsLabel.GetPreferredSize(new Size(maxLineDx, 13));
            SeeResultsLabel.Size = preferredSize;
            SeeResultsLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkLabel_Clicked);
            y += (preferredSize.Height + buttonExit.Size.Height + 30);
            this.Controls.Add(SeeResultsLabel);
            if (ClientSize.Height < y)
                ClientSize = new Size(this.ClientSize.Width, y);
        }
Esempio n. 6
0
 private Size CreateText(int x, int y, int lineHeight, string text)
 {
     Label label = new Label();
     label.BackColor = SystemColors.Info;
     label.ForeColor = SystemColors.InfoText;
     label.Location = new Point(x, y);
     label.Text = text;
     Size clientSize = base.ClientSize;
     clientSize.Width = clientSize.Width - SystemInformation.VerticalScrollBarWidth - x;
     Size preferredSize = label.GetPreferredSize(clientSize);
     label.Size = preferredSize;
     if (lineHeight > 0)
     {
         label.Location = new Point(x, y + (lineHeight - label.Size.Height) / 2);
     }
     base.Controls.Add(label);
     return label.Size;
 }