Skip to content

Commit

Permalink
CustomMessageBox: add ShowTextBox text selectable option
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jun 21, 2024
1 parent 1b1880c commit 3e8f11f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
73 changes: 64 additions & 9 deletions ExtLibs/Controls/CustomMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using MissionPlanner.Controls;
using System.Threading;
using TextBox = System.Windows.Forms.TextBox;

namespace MissionPlanner.MsgBox
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
}
3 changes: 2 additions & 1 deletion ExtLibs/Controls/ProgressReporterDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down

0 comments on commit 3e8f11f

Please sign in to comment.