Ejemplo n.º 1
0
        public WideMessageBox(WideMessageBoxArgs args)
        {
            InitializeComponent();

            Setup(args);

            //can only write to clipboard in STA threads
            btnCopyToClipboard.Visible = Thread.CurrentThread.GetApartmentState() == ApartmentState.STA;

            //try to resize form to fit bounds
            this.Size = GetPreferredSizeOfTextControl(richTextBox1);
            this.Size = new Size(this.Size.Width + 10, this.Size.Height + 150);//leave a bit of padding

            var theScreen = Screen.FromControl(this);

            //enforce sensible max/min sizes
            Width = Math.Min(Math.Max(600, Width), theScreen.Bounds.Width - 400);

            //if the text is too long vertically just maximise the message box
            if (this.Height > theScreen.Bounds.Height)
            {
                this.WindowState = FormWindowState.Maximized;
            }

            richTextBox1.LinkClicked += richTextBox1_LinkClicked;
            btnViewSourceCode.Click  += (s, e) => new ViewSourceCodeDialog((string)btnViewSourceCode.Tag).Show();
        }
Ejemplo n.º 2
0
        private void Setup(WideMessageBoxArgs args)
        {
            Args = args;

            btnBack.Enabled = _navigationStack.Any();

            btnViewStackTrace.Visible = args.EnvironmentDotStackTrace != null;

            richTextBox1.Font = new Font(FontFamily.GenericMonospace, richTextBox1.Font.Size);
            richTextBox1.Select(0, 0);
            richTextBox1.WordWrap = true;
            richTextBox1.Text     = "";

            var message = args.Message;
            var title   = args.Title;

            //todo hack:if theres a long title and no message
            if (!string.IsNullOrWhiteSpace(title) && string.IsNullOrWhiteSpace(message) && title.Length > 100)
            {
                message = title;
                title   = null;
            }

            //Replace single newlines with double new lines
            if (Args.FormatAsParagraphs && CommentStore != null)
            {
                message = CommentStore.FormatAsParagraphs(message);
            }

            //if there is a title
            if (!string.IsNullOrWhiteSpace(title))
            {
                lblMainMessage.Text = title.Length > MAX_LENGTH_TITLE?title.Substring(0, MAX_LENGTH_TITLE) : title;
            }
            else
            {
                richTextBox1.Top       = lblMainMessage.Top;
                richTextBox1.Height   += lblMainMessage.Top;
                lblMainMessage.Visible = false;
            }

            SetMessage(message, args.KeywordNotToAdd);

            ApplyTheme(args.Theme);

            if (args.Theme == WideMessageBoxTheme.Help)
            {
                SetViewSourceCodeButton(args.Title);
            }
        }