diff --git a/ExtLibs/Controls/CustomMessageBox.cs b/ExtLibs/Controls/CustomMessageBox.cs index fa27d80348..d8649c252d 100644 --- a/ExtLibs/Controls/CustomMessageBox.cs +++ b/ExtLibs/Controls/CustomMessageBox.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using MissionPlanner.Controls; using System.Threading; +using TextBox = System.Windows.Forms.TextBox; namespace MissionPlanner.MsgBox { @@ -69,7 +70,7 @@ public static DialogResult Show(string text, string caption, MessageBoxButtons b return answer; } - static DialogResult ShowUI(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, string YesText = "Yes", string NoText = "No") + static DialogResult ShowUI(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, string YesText = "Yes", string NoText = "No", bool label = true) { DialogResult answer = DialogResult.Abort; @@ -123,15 +124,35 @@ static DialogResult ShowUI(string text, string caption, MessageBoxButtons button Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle); int titleHeight = screenRectangle.Top - msgBoxFrm.Top; - var lblMessage = new Label + Control lblMessage = null; + + if (label) { - Left = 58, - Top = 15, - Width = textSize.Width + 10, - Height = textSize.Height + 10, - Text = text, - AutoSize = true - }; + lblMessage = new Label() + { + Left = 58, + Top = 15, + Width = textSize.Width + 10, + Height = textSize.Height + 10, + Text = text, + AutoSize = true + }; + } + else + { + lblMessage = new TextBox() + { + ReadOnly = true, + Multiline = true, + Left = 58, + Top = 15, + Width = textSize.Width + 10, + Height = Math.Min( textSize.Height + 10, 500), + Text = text, + AutoSize = true, + ScrollBars = ScrollBars.Vertical + }; + } msgBoxFrm.Controls.Add(lblMessage); @@ -353,5 +374,39 @@ private static Icon getMessageBoxIcon(MessageBoxIcon icon) } } + public static DialogResult ShowTextBox(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, string YesText = "Yes", string NoText = "No") + { + DialogResult answer = DialogResult.Cancel; + + Console.WriteLine("CustomMessageBox ShowTextBox thread calling " + System.Threading.Thread.CurrentThread.Name); + + // ensure we run this on the right thread - mono - mac + if (Application.OpenForms.Count > 0 && Application.OpenForms[0].InvokeRequired) + { + try + { + Application.OpenForms[0].Invoke((Action)delegate + { + Console.WriteLine("CustomMessageBox ShowTextBox thread running invoke " + + System.Threading.Thread.CurrentThread.Name); + answer = ShowUI(text, caption, buttons, icon, YesText, NoText, false); + }); + } + catch (Exception ex) + { + Console.WriteLine(ex); + // fall back + Console.WriteLine("CustomMessageBox ShowTextBox thread running " + System.Threading.Thread.CurrentThread.Name); + answer = ShowUI(text, caption, buttons, icon, YesText, NoText, false); + } + } + else + { + Console.WriteLine("CustomMessageBox ShowTextBox thread running " + System.Threading.Thread.CurrentThread.Name); + answer = ShowUI(text, caption, buttons, icon, YesText, NoText, false); + } + + return answer; + } } } \ No newline at end of file diff --git a/ExtLibs/Controls/ProgressReporterDialogue.cs b/ExtLibs/Controls/ProgressReporterDialogue.cs index 7fed44ad82..3c5ded6a60 100644 --- a/ExtLibs/Controls/ProgressReporterDialogue.cs +++ b/ExtLibs/Controls/ProgressReporterDialogue.cs @@ -301,7 +301,8 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs + Environment.NewLine + Environment.NewLine + this.workerException.StackTrace; - MsgBox.CustomMessageBox.Show(message,"Exception Details",MessageBoxButtons.OK,MessageBoxIcon.Information); + MsgBox.CustomMessageBox.ShowTextBox(message, "Exception Details", MessageBoxButtons.OK, + MessageBoxIcon.Information); } ///