//
// Copyright © 2012 Deltares
//
// Author: André Hendriks (andre.hendriks@deltares.nl)
//
// THE WORK (AS DEFINED IN THE Code Project Open License, see http://www.codeproject.com/info/cpol10.aspx)
// IS PROVIDED UNDER THE TERMS OF THIS CODE PROJECT OPEN LICENSE ("LICENSE").
// THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF
// THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
//
// BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HEREIN, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS
// OF THIS LICENSE. THE AUTHOR GRANTS YOU THE RIGHTS CONTAINED HEREIN IN CONSIDERATION OF YOUR
// ACCEPTANCE OF SUCH TERMS AND CONDITIONS. IF YOU DO NOT AGREE TO ACCEPT AND BE BOUND BY THE TERMS OF
// THIS LICENSE, YOU CANNOT MAKE ANY USE OF THE WORK.
//
using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
#pragma warning disable 1587 // For Doxygen, it is handy to have a XML directive on a namespace, even if Visual Studio thinks it's invalid.
/// <summary>Namespace containing extra WinForm controls or extended versions of such controls.</summary>
#pragma warning restore 1587
namespace Deltares.Controls
{
/// <summary>
/// Extended MessageBox (static) class.
///
/// Extended MessageBox (static) class. Provides all the methods the MessageBox class provides,
/// but adds a version where a structure with extra settings is passed in. Also obeys the CurrentUICulture
/// setting for the text displayed on the buttons, as far as these resources are defined in the satellite
/// assemblies.
/// <seealso cref="Deltares.Controls.MessageBoxExtras"/>
/// <seealso cref="System.Windows.Forms.MessageBox"/>
/// </summary>
public static class MessageBoxEx
{
#region Private and internal fields and properties
private static System.Windows.Forms.ProgressBar _progress = null;
private static DialogResult answer = DialogResult.OK;
private static bool attachHandlers = true;
private static bool buttonPressed = false;
private static HelpNavigator _helpNavigator = HelpNavigator.TableOfContents;
private static string _helpFilePath = null;
private static string _helpKeyWord = null;
private static object _helpParam = null;
private static System.Windows.Forms.MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1;
private static System.Windows.Forms.Button[] formButtons;
private static System.Windows.Forms.PictureBox iconBox;
private static System.Windows.Forms.Label labelText;
private static object lockObject = new object();
private static System.Windows.Forms.Form msgForm = new System.Windows.Forms.Form();
private static int nrButtons;
private static global::System.Resources.ResourceManager resourceMan;
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
lock (lockObject)
{
if (object.ReferenceEquals(resourceMan, null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Deltares.Controls.MessageBoxEx", typeof(MessageBoxEx).Assembly);
resourceMan = temp;
}
}
return resourceMan;
}
}
private static bool timedOut = false;
private static System.Threading.Timer timer = null;
private const int timerInterval = 200;
private delegate void timerTickCallback(object state);
#endregion
#region Public fields and methods
/// <summary>
/// Displays a message box with specified text.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text)
{
msgForm.Owner = null;
initializeComponent(text, null,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text)
{
msgForm.Owner = null;
initializeComponent(text, null,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with specified text and caption.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption)
{
msgForm.Owner = null;
initializeComponent(text, caption,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text and caption.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, and buttons.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption and buttons.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with specified text, caption, buttons, and icon.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption, buttons and icon.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon and default button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption, buttons, icon and default button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button and options.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, default button and options.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="displayHelpButton">True to display the help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
displayHelpButton, HelpNavigator.TableOfContents, null, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.TableOfContents, helpFilePath, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.TableOfContents, helpFilePath, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="keyword">The Help keyword to display when the user clicks the Help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.KeywordIndex, helpFilePath, keyword, null, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="keyword">The Help keyword to display when the user clicks the Help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.KeywordIndex, helpFilePath, keyword, null, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <param name="param">The numeric ID of the Help topic to display when the user clicks the Help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator, object param)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, param, null);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <param name="param">The numeric ID of the Help topic to display when the user clicks the Help button.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator, object param)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, param, null);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with specified text.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, null,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, null,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with specified text and caption.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text and caption.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, and buttons.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption and buttons.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
System.Windows.Forms.MessageBoxIcon.None,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with specified text, caption, buttons, and icon.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption, buttons and icon.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon and default button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption, buttons, icon and default button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button and options.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, default button and options.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
false, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="displayHelpButton">True to display the help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
displayHelpButton, HelpNavigator.TableOfContents, null, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.TableOfContents, helpFilePath, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.TableOfContents, helpFilePath, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="keyword">The Help keyword to display when the user clicks the Help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.KeywordIndex, helpFilePath, keyword, null, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="keyword">The Help keyword to display when the user clicks the Help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, HelpNavigator.KeywordIndex, helpFilePath, keyword, null, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <param name="param">The numeric ID of the Help topic to display when the user clicks the Help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator, object param, MessageBoxExtras extras)
{
msgForm.Owner = null;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, param, extras);
answer = msgForm.ShowDialog();
return answer;
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
/// </summary>
/// <param name="owner">An implementation of System.Windows.Forms.IWin32Window that will own the modal dialogbox.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the System.Windows.Forms.MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the System.Windows.Forms.MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies the default button for the message box.</param>
/// <param name="options">One of the System.Windows.Forms.MessageBoxOptions values that specifies which display and associated options will be used for the message box. <strong>Ignored in this version</strong>.</param>
/// <param name="helpFilePath">The path and name of the Help file to display when the user clicks the Help button.</param>
/// <param name="helpNavigator">One of the System.Windows.Forms.HelpNavigator values.</param>
/// <param name="param">The numeric ID of the Help topic to display when the user clicks the Help button.</param>
/// <param name="extras">Extra information for the messagebox construction and functionality.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator helpNavigator, object param, MessageBoxExtras extras)
{
msgForm.Owner = (System.Windows.Forms.Form)owner;
initializeComponent(text, caption,
buttons,
icon,
defaultButton,
true, helpNavigator, helpFilePath, null, param, extras);
answer = msgForm.ShowDialog(owner);
return answer;
}
#endregion
#region Private methods
private static void attachFocusHandlers(System.Windows.Forms.Button[] buttons)
{
foreach (System.Windows.Forms.Button button in buttons) button.GotFocus += new EventHandler(button_Focussed);
}
private static void button_Focussed(object sender, EventArgs e)
{
// Move the acceptbutton (button "clicked" when <ENTER> is pressed) to the active buttton:
System.Windows.Forms.Button button = sender as System.Windows.Forms.Button;
msgForm.AcceptButton = button;
}
private static void button_Click(object sender, EventArgs e)
{
System.Windows.Forms.Button button = sender as System.Windows.Forms.Button;
string tag = (string)button.Tag;
if (tag.Equals("buttonTextHelp"))
{
showHelp(_helpFilePath, _helpNavigator, _helpKeyWord, _helpParam);
}
else
{
msgForm.DialogResult = getDialogResult(tag);
buttonPressed = true;
msgForm.Close();
}
}
private static void detachFocusHandlers(System.Windows.Forms.Button[] buttons)
{
foreach (System.Windows.Forms.Button button in buttons) button.GotFocus -= new EventHandler(button_Focussed);
}
private static void formActivated(object sender, EventArgs e)
{
try
{
for (int b = 0; b < nrButtons; b++)
{
formButtons[b].NotifyDefault(false);
}
if (defaultButton == MessageBoxDefaultButton.Button1)
{
//formButtons[0].Focus();
formButtons[0].NotifyDefault(true);
//msgForm.AcceptButton = formButtons[0];
msgForm.ActiveControl = formButtons[0];
}
else if (defaultButton == MessageBoxDefaultButton.Button2)
{
//formButtons[1].Focus();
formButtons[1].NotifyDefault(true);
//msgForm.AcceptButton = formButtons[1];
msgForm.ActiveControl = formButtons[1];
}
else if (defaultButton == MessageBoxDefaultButton.Button3)
{
//formButtons[2].Focus();
formButtons[2].NotifyDefault(true);
//msgForm.AcceptButton = formButtons[2];
msgForm.ActiveControl = formButtons[2];
}
}
catch (Exception)
{
}
}
private static void formClosing(object sender, FormClosingEventArgs e)
{
// Cancel the close if closing via controlbox, and not because a button was pressed or the
// form timed out (except when we can predict the choice):
if ((e.CloseReason == CloseReason.UserClosing) && (!buttonPressed) && (!timedOut) && (nrButtons > 1))
{
e.Cancel = true;
}
else
{
if (timer != null)
{
timer.Dispose();
}
if (!buttonPressed)
{
int buttonIndex = 0;
if (defaultButton == MessageBoxDefaultButton.Button2) buttonIndex = 1;
if (defaultButton == MessageBoxDefaultButton.Button3) buttonIndex = 2;
msgForm.DialogResult = getDialogResult((string)formButtons[buttonIndex].Tag);
}
int start = msgForm.Controls.Count - 1;
for (int c = start; c >= 0; c--)
{
msgForm.Controls.RemoveAt(c);
}
}
}
private static string[] getButtonCaptions(string[] buttonCapKeys)
{
string[] captions = new string[buttonCapKeys.Length];
for (int j = 0; j < buttonCapKeys.Length; j++)
{
if (buttonCapKeys[j].Equals("buttonTextAbort"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextAbort;
else if (buttonCapKeys[j].Equals("buttonTextCancel"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextCancel;
else if (buttonCapKeys[j].Equals("buttonTextIgnore"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextIgnore;
else if (buttonCapKeys[j].Equals("buttonTextNo"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextNo;
else if (buttonCapKeys[j].Equals("buttonTextOK"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextOK;
else if (buttonCapKeys[j].Equals("buttonTextRetry"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextRetry;
else if (buttonCapKeys[j].Equals("buttonTextTryAgain"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextRetry;
else if (buttonCapKeys[j].Equals("buttonTextYes"))
captions[j] = Deltares.Controls.Properties.Resources.buttonTextYes;
if (string.IsNullOrEmpty(captions[j])) captions[j] = buttonCapKeys[j].Replace("buttonText", "&");
}
return captions;
}
private static DialogResult getDialogResult(string tag)
{
if (tag.Equals("buttonTextAbort"))
return DialogResult.Abort;
else if (tag.Equals("buttonTextCancel"))
return DialogResult.Cancel;
else if (tag.Equals("buttonTextIgnore"))
return DialogResult.Ignore;
else if (tag.Equals("buttonTextNo"))
return DialogResult.No;
else if (tag.Equals("buttonTextOK"))
return DialogResult.OK;
else if (tag.Equals("buttonTextRetry"))
return DialogResult.Retry;
else if (tag.Equals("buttonTextTryAgain"))
return DialogResult.Retry;
else if (tag.Equals("buttonTextYes"))
return DialogResult.Yes;
else
return DialogResult.None;
}
private static string getHelpFilePath(string filePath)
{
bool helpDefined = ((!String.IsNullOrEmpty(filePath)) && System.IO.File.Exists(filePath));
if (helpDefined)
return filePath;
else
{
// If no help file is defined, try if one of the forms in the
// entry assembly has a helpprovider defined:
try
{
Assembly ass = Assembly.GetEntryAssembly();
Type[] types = ass.GetTypes();
foreach (Type type in types)
{
if (type.BaseType.Equals(typeof(System.Windows.Forms.Form)))
{
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fi in fields)
{
if (fi.FieldType.Equals(typeof(System.Windows.Forms.HelpProvider)))
{
// Yes, we have a form with a HelpProvider. Use reflection to create an instance if it:
object inst = Activator.CreateInstance(type);
System.Windows.Forms.HelpProvider hp = fi.GetValue(inst) as System.Windows.Forms.HelpProvider;
// If we have succeeded and the provider has a non-null HelpNamespace, take the value as the helpfile:
if ((hp != null) && (hp.HelpNamespace != null))
{
return hp.HelpNamespace;
}
}
}
}
}
}
catch (Exception)
{
}
}
// Nothing found. Return null name:
return null;
}
/// <summary>
/// Create a form of the correct dimension and with the correct buttons.
/// </summary>
private static void initializeComponent(string text, string caption,
System.Windows.Forms.MessageBoxButtons buttons,
System.Windows.Forms.MessageBoxIcon icon,
System.Windows.Forms.MessageBoxDefaultButton defButton,
bool helpButton, HelpNavigator helpNavigator, string helpFilePath, string helpKeyWord, object helpParam,
MessageBoxExtras extras)
{
int x, y, margin;
int buttonHeight, buttonWidth, captionWidth, formHeight, formWidth, iconHeight, iconWidth, textHeight, textWidth;
int progressHeight = 0;
int checkHeight = 0;
string[] buttonCapKeys = null;
string[] buttonCaps = null;
buttonPressed = false;
timedOut = false;
defaultButton = defButton;
_helpNavigator = helpNavigator;
_helpFilePath = getHelpFilePath(helpFilePath);
_helpKeyWord = helpKeyWord;
_helpParam = helpParam;
msgForm.SuspendLayout();
// TODO: adjust for font, etc.
x = 12;
y = 12;
margin = 6;
iconHeight = iconWidth = 0;
//// Icon ////
if ((icon != MessageBoxIcon.None) || ((extras != null) && (extras.Icon != null)))
{
iconHeight = iconWidth = 32;
iconBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(iconBox)).BeginInit();
//
// iconBox
//
if ((extras != null) && (extras.Icon != null))
{
iconBox.Image = extras.Icon.ToBitmap();
}
else
{
switch (icon)
{
case MessageBoxIcon.Asterisk: iconBox.Image = System.Drawing.SystemIcons.Asterisk.ToBitmap(); break;
case MessageBoxIcon.Error: iconBox.Image = System.Drawing.SystemIcons.Error.ToBitmap(); break;
case MessageBoxIcon.Question: iconBox.Image = System.Drawing.SystemIcons.Question.ToBitmap(); break;
case MessageBoxIcon.Warning: iconBox.Image = System.Drawing.SystemIcons.Warning.ToBitmap(); break;
}
}
iconBox.Location = new System.Drawing.Point(x, y);
iconBox.Name = "iconBox";
iconBox.Size = new System.Drawing.Size(iconWidth, iconHeight);
iconBox.TabIndex = 0;
iconBox.TabStop = false;
msgForm.Controls.Add(iconBox);
((System.ComponentModel.ISupportInitialize)(iconBox)).EndInit();
}
//// Buttons ////
if (helpButton)
{
switch (buttons)
{
case System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore:
buttonCapKeys = new string[] { "buttonTextAbort", "buttonTextRetry", "buttonTextIgnore", "buttonTextHelp" }; break;
case System.Windows.Forms.MessageBoxButtons.OK:
buttonCapKeys = new string[] { "buttonTextOK", "buttonTextHelp"}; break;
case System.Windows.Forms.MessageBoxButtons.OKCancel:
buttonCapKeys = new string[] { "buttonTextOK", "buttonTextCancel", "buttonTextHelp" }; break;
case System.Windows.Forms.MessageBoxButtons.RetryCancel:
buttonCapKeys = new string[] { "buttonTextRetry", "buttonTextCancel", "buttonTextHelp" }; break;
case System.Windows.Forms.MessageBoxButtons.YesNo:
buttonCapKeys = new string[] { "buttonTextYes", "buttonTextNo", "buttonTextHelp" }; break;
case System.Windows.Forms.MessageBoxButtons.YesNoCancel:
buttonCapKeys = new string[] { "buttonTextYes", "buttonTextNo", "buttonTextCancel", "buttonTextHelp" }; break;
}
}
else
{
switch (buttons)
{
case System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore:
buttonCapKeys = new string[] { "buttonTextAbort", "buttonTextRetry", "buttonTextIgnore" }; break;
case System.Windows.Forms.MessageBoxButtons.OK:
buttonCapKeys = new string[] { "buttonTextOK" }; break;
case System.Windows.Forms.MessageBoxButtons.OKCancel:
buttonCapKeys = new string[] { "buttonTextOK", "buttonTextCancel" }; break;
case System.Windows.Forms.MessageBoxButtons.RetryCancel:
buttonCapKeys = new string[] { "buttonTextRetry", "buttonTextCancel" }; break;
case System.Windows.Forms.MessageBoxButtons.YesNo:
buttonCapKeys = new string[] { "buttonTextYes", "buttonTextNo" }; break;
case System.Windows.Forms.MessageBoxButtons.YesNoCancel:
buttonCapKeys = new string[] { "buttonTextYes", "buttonTextNo", "buttonTextCancel" }; break;
}
}
nrButtons = buttonCapKeys.Length;
// Check that defaultButton is not too large for nr of buttons:
if (helpButton)
{
if (nrButtons == 3) // two normal + 1 help
if (defaultButton == MessageBoxDefaultButton.Button3) defaultButton = MessageBoxDefaultButton.Button2;
else if (nrButtons == 2) // one normal + 1 help
defaultButton = MessageBoxDefaultButton.Button1;
}
else
{
if (nrButtons == 2) // two normal
if (defaultButton == MessageBoxDefaultButton.Button3) defaultButton = MessageBoxDefaultButton.Button2;
else if (nrButtons == 1) // one normal
defaultButton = MessageBoxDefaultButton.Button1;
}
// Translate the captions
buttonCaps = getButtonCaptions(buttonCapKeys);
// Now we know the number of buttons and whether to show an icon, we can determine the various sizes:
if (extras != null)
{
if (extras.ProgressBar != null)
{
progressHeight = extras.ProgressBar.Height;
// Maximize time-out to 1 days:
if (extras.ProgressBar.Maximum > 86400000) extras.ProgressBar.Maximum = 86400000;
}
if (extras.CheckBox != null) checkHeight = 1;
if (extras.Font != null)
measureSizes(extras.Font, caption, text, nrButtons, iconWidth, progressHeight, ref checkHeight,
out margin, out captionWidth,
out buttonHeight, out buttonWidth,
out formHeight, out formWidth,
out textHeight, out textWidth);
else
measureSizes(msgForm.Font, caption, text, nrButtons, iconWidth, progressHeight, ref checkHeight,
out margin, out captionWidth,
out buttonHeight, out buttonWidth,
out formHeight, out formWidth,
out textHeight, out textWidth);
}
else
{
int dummy = 0;
measureSizes(msgForm.Font, caption, text, nrButtons, iconWidth, 0, ref dummy,
out margin, out captionWidth,
out buttonHeight, out buttonWidth,
out formHeight, out formWidth,
out textHeight, out textWidth);
}
if (formButtons != null) detachFocusHandlers(formButtons);
formButtons = new System.Windows.Forms.Button[nrButtons];
int bW = nrButtons * buttonWidth + (nrButtons + 1) * margin;
if (bW < formWidth)
x = margin + (formWidth - bW) / 2;
else
x = margin;
y = max(textHeight, iconHeight, 0) + 2 * margin;
for (int b = 0; b < nrButtons; b++)
{
formButtons[b] = new System.Windows.Forms.Button();
//
// button
//
formButtons[b].Location = new System.Drawing.Point(x, y);
formButtons[b].Name = "button_" + b.ToString();
formButtons[b].RightToLeft = RightToLeft.Inherit;
formButtons[b].Size = new System.Drawing.Size(buttonWidth, buttonHeight);
formButtons[b].TabIndex = 2 + b;
formButtons[b].TabStop = true;
formButtons[b].Text = buttonCaps[b];
formButtons[b].Tag = buttonCapKeys[b];
formButtons[b].UseVisualStyleBackColor = true;
formButtons[b].Click += new EventHandler(button_Click);
msgForm.Controls.Add(formButtons[b]);
if (formButtons[b].Tag.Equals("buttonTextCancel"))
msgForm.CancelButton = formButtons[b];
x += (buttonWidth + margin);
}
attachFocusHandlers(formButtons);
//// Text label ////
x = margin + iconWidth;
if (iconWidth > 0) x += margin;
y = margin;
labelText = new System.Windows.Forms.Label();
labelText.AutoSize = false;
labelText.BorderStyle = System.Windows.Forms.BorderStyle.None;
labelText.Location = new System.Drawing.Point(x, y);
labelText.Name = "labelText";
labelText.RightToLeft = RightToLeft.Inherit;
labelText.Size = new System.Drawing.Size(textWidth, textHeight);
labelText.TabIndex = 1;
labelText.Text = text;
labelText.TextAlign = ContentAlignment.MiddleLeft;
msgForm.Controls.Add(labelText);
//// Checkbox ////
if ((extras != null) && (extras.CheckBox != null))
{
x = margin;
y = formHeight - progressHeight - checkHeight - (int)(0.2 * margin);
extras.CheckBox.Location = new System.Drawing.Point(x, y);
extras.CheckBox.RightToLeft = RightToLeft.Inherit; // probably that will not be set...
extras.CheckBox.Size = new System.Drawing.Size(formWidth - 2 * margin, checkHeight);
msgForm.Controls.Add(extras.CheckBox);
}
//// ProgressBar ////
if ((extras != null) && (extras.ProgressBar != null))
{
_progress = extras.ProgressBar;
x = margin;
y = formHeight - progressHeight - (int)(0.2 * margin);
_progress.Location = new System.Drawing.Point(x, y);
_progress.Size = new System.Drawing.Size(formWidth - 2 * margin, progressHeight);
_progress.Minimum = 0;
_progress.Value = _progress.Maximum;
msgForm.Controls.Add(_progress);
timer = new System.Threading.Timer(timer_Tick, null, timerInterval, timerInterval);
}
//
// MessageBoxEx
//
msgForm.AllowTransparency = true;
msgForm.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
msgForm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
msgForm.ClientSize = new System.Drawing.Size(formWidth, formHeight);
msgForm.ControlBox = true;
msgForm.DialogResult = DialogResult.None;
msgForm.FormBorderStyle = FormBorderStyle.FixedDialog;
msgForm.Icon = null;
msgForm.MaximizeBox = false;
msgForm.MinimizeBox = false;
msgForm.Name = "MessageBoxEx";
if (System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft)
{
msgForm.RightToLeft = RightToLeft.Yes;
msgForm.RightToLeftLayout = true;
}
else
{
msgForm.RightToLeft = RightToLeft.No;
msgForm.RightToLeftLayout = false;
}
msgForm.ShowIcon = false;
msgForm.ShowInTaskbar = false;
msgForm.Text = caption;
msgForm.TopMost = true;
msgForm.StartPosition = FormStartPosition.CenterScreen;
// Check extras for additional/different values:
if (extras != null)
{
if (extras.BackColor != null)
{
msgForm.BackColor = extras.BackColor;
for (int b = 0; b < nrButtons; b++) formButtons[b].BackColor = extras.BackColor;
}
if ((extras.CenterOwner) && (msgForm.Owner != null))
{
msgForm.StartPosition = FormStartPosition.CenterParent;
}
if (extras.Font != null)
{
msgForm.Font = extras.Font;
for (int b = 0; b < nrButtons; b++) formButtons[b].Font = extras.Font;
}
if (extras.ForeColor != null)
{
msgForm.ForeColor = extras.ForeColor;
for (int b = 0; b < nrButtons; b++) formButtons[b].ForeColor = extras.ForeColor;
}
if ((extras.Opacity >= 0.0) && (extras.Opacity <= 1.0))
msgForm.Opacity = extras.Opacity;
}
lock (lockObject)
{
if (attachHandlers)
{
msgForm.FormClosing += new FormClosingEventHandler(formClosing);
msgForm.Activated += new EventHandler(formActivated);
attachHandlers = false;
}
}
msgForm.ResumeLayout(false);
}
private static int max(int x1, int x2, int x3)
{
int r = x1;
if (x2 > r) r = x2;
if (x3 > r) r = x3;
return r;
}
private static System.Drawing.SizeF measureButtons(Font usedFont)
{
SizeF maxSize = new Size(1,1);
SizeF size;
// Measure all button captions in current culture and find widest:
size = measureString(Deltares.Controls.Properties.Resources.buttonTextAbort , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextCancel , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextIgnore , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextNo , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextOK , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextRetry , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextTryAgain, usedFont);
if (size.Width > maxSize.Width) maxSize = size;
size = measureString(Deltares.Controls.Properties.Resources.buttonTextYes , usedFont);
if (size.Width > maxSize.Width) maxSize = size;
// Apply padding:
maxSize = new SizeF((int)(1.6f * maxSize.Width), (int)(1.75f * maxSize.Height));
return maxSize;
}
private static void measureSizes(Font usedFont, string caption, string text, int nrButtons, int iconSize,
int progressHeight, ref int checkHeight,
out int margin, out int captionWidth,
out int buttonHeight, out int buttonWidth,
out int formHeight, out int formWidth,
out int textHeight, out int textWidth)
{
SizeF size = measureString(caption, usedFont);
captionWidth = (int)size.Width;
size = measureString(text, usedFont);
textHeight = (int)size.Height;
textWidth = (int)size.Width;
size = measureString("Ag", usedFont);
margin = (int)size.Width;
if (checkHeight != 0) checkHeight = (int)(1.3 * size.Height);
size = measureButtons(usedFont);
buttonWidth = (int)size.Width;
buttonHeight = (int)size.Height;
int use = iconSize;
if (textHeight > iconSize) use = textHeight;
formHeight = 3 * margin + use + buttonHeight + checkHeight + progressHeight;
if (checkHeight > 0) formHeight += (int)(0.2 * margin);
if (progressHeight > 0) formHeight += (int)(0.2 * margin);
if (iconSize == 0)
formWidth = max(margin + nrButtons * (buttonWidth + margin), textWidth + 2 * margin, (int)(1.1 * captionWidth) + 30 + 2 * margin);
else
formWidth = max(margin + nrButtons * (buttonWidth + margin), iconSize + textWidth + 3 * margin, (int)(1.1 * captionWidth) + 30 + 2 * margin); // allow for close button
}
private static SizeF measureString(string text, Font usedFont)
{
Bitmap img = new Bitmap(100, 20);
Graphics graphics = Graphics.FromImage(img);
SizeF returnValue = graphics.MeasureString(text, usedFont);
graphics = null;
return returnValue;
}
private static void showHelp(string helpFilePath, HelpNavigator helpType, string keyword, object parameter)
{
if (System.IO.File.Exists(helpFilePath))
{
// Show the requested help:
if (!String.IsNullOrEmpty(keyword))
Help.ShowHelp(msgForm, helpFilePath, helpType, keyword);
else
Help.ShowHelp(msgForm, helpFilePath, helpType, parameter);
}
}
private static void timer_Tick(object state)
{
if (_progress.InvokeRequired)
{
timerTickCallback cb = new timerTickCallback(timer_Tick);
_progress.BeginInvoke(cb, new object[] { state });
}
else
{
if ((_progress.Value - timerInterval) < _progress.Minimum)
{
timedOut = true;
msgForm.Close();
}
else
{
_progress.Value -= timerInterval;
_progress.Refresh();
}
Application.DoEvents();
}
}
#endregion
}
}