Skip to content

Commit

Permalink
* Try to implement point 4 of #728
Browse files Browse the repository at this point in the history
  • Loading branch information
PWagner1 committed Jul 17, 2022
1 parent 51deea4 commit 32350af
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 75 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ internal partial class KryptonMessageBoxForm : KryptonForm
#endregion

#region Instance Fields
private readonly bool _showHelpButton;
private readonly string _text;
private readonly string _caption;
private readonly string _helpPath;
private readonly MessageBoxButtons _buttons;
private readonly KryptonMessageBoxIcon _kryptonMessageBoxIcon;
private readonly MessageBoxIcon _messageBoxIcon;

private readonly MessageBoxDefaultButton _defaultButton;
private readonly KryptonMessageBoxDefaultButton _defaultButton;
private readonly MessageBoxOptions _options; // https://github.com/Krypton-Suite/Standard-Toolkit/issues/313
// If help information provided or we are not a service/default desktop application then grab an owner for showing the message box
private readonly IWin32Window _showOwner;
Expand All @@ -45,9 +47,10 @@ public KryptonMessageBoxForm()


internal KryptonMessageBoxForm(IWin32Window showOwner, string text, string caption,
MessageBoxButtons buttons, KryptonMessageBoxIcon icon,
MessageBoxDefaultButton defaultButton, MessageBoxOptions options,
HelpInfo helpInfo, bool? showCtrlCopy)
MessageBoxButtons buttons, KryptonMessageBoxIcon icon,
KryptonMessageBoxDefaultButton defaultButton, MessageBoxOptions options,
HelpInfo helpInfo, bool? showCtrlCopy,
bool? showHelpButton, string helpPath)
{
// Store incoming values
_text = text;
Expand All @@ -58,6 +61,8 @@ internal KryptonMessageBoxForm(IWin32Window showOwner, string text, string capti
_options = options;
_helpInfo = helpInfo;
_showOwner = showOwner;
_helpPath = helpPath;
_showHelpButton = showHelpButton ?? false;

// Create the form contents
InitializeComponent();
Expand All @@ -72,14 +77,18 @@ internal KryptonMessageBoxForm(IWin32Window showOwner, string text, string capti
UpdateHelp();
UpdateTextExtra(showCtrlCopy);

// Show the help button?
_button5.Visible = _showHelpButton;

// Finally calculate and set form sizing
UpdateSizing(showOwner);
}

internal KryptonMessageBoxForm(IWin32Window showOwner, string text, string caption,
MessageBoxButtons buttons, MessageBoxIcon icon,
MessageBoxDefaultButton defaultButton, MessageBoxOptions options,
HelpInfo helpInfo, bool? showCtrlCopy)
MessageBoxButtons buttons, MessageBoxIcon icon,
KryptonMessageBoxDefaultButton defaultButton, MessageBoxOptions options,
HelpInfo helpInfo, bool? showCtrlCopy,
bool? showHelpButton, string helpPath)
{
// Store incoming values
_text = text;
Expand All @@ -90,6 +99,8 @@ internal KryptonMessageBoxForm(IWin32Window showOwner, string text, string capti
_options = options;
_helpInfo = helpInfo;
_showOwner = showOwner;
_helpPath = helpPath;
_showHelpButton = showHelpButton ?? false;

// Create the form contents
InitializeComponent();
Expand All @@ -104,6 +115,9 @@ internal KryptonMessageBoxForm(IWin32Window showOwner, string text, string capti
UpdateHelp();
UpdateTextExtra(showCtrlCopy);

// Show the help button?
_button5.Visible = _showHelpButton;

// Finally calculate and set form sizing
UpdateSizing(showOwner);

Expand Down Expand Up @@ -337,26 +351,40 @@ private void UpdateButtons()
#endif
}

// Set the text for the "Help" button
if (_button5.Visible)
{
_button5.Text = KryptonManager.Strings.Help;
kcmdButton5.Text = KryptonManager.Strings.Help;
}

// Do we ignore the Alt+F4 on the buttons?
if (!ControlBox)
{
_button1.IgnoreAltF4 = true;
_button2.IgnoreAltF4 = true;
_button3.IgnoreAltF4 = true;
_button4.IgnoreAltF4 = true;
_button5.IgnoreAltF4 = true;
}
}

private void UpdateDefault()
{
switch (_defaultButton)
{
case MessageBoxDefaultButton.Button2:
case KryptonMessageBoxDefaultButton.Button2:
_button2.Select();
break;
case MessageBoxDefaultButton.Button3:
case KryptonMessageBoxDefaultButton.Button3:
_button3.Select();
break;
case KryptonMessageBoxDefaultButton.Button4:
_button5.Select();
break;
default:
_button5.Select();
break;
}
}

Expand Down Expand Up @@ -587,6 +615,20 @@ private void AnyKeyDown(object sender, KeyEventArgs e)
Clipboard.SetText(sb.ToString(), TextDataFormat.UnicodeText);
}

private void kcmdButton5_Execute(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrWhiteSpace(_helpPath))
{
Process.Start(_helpPath);
}
}
catch (Exception exc)
{
ExceptionHandler.CaptureException(exc);
}
}
}

#region Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="kcmdButton5.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class GlobalStrings : GlobalId
// NET 6 & newer
private const string DEFAULT_CONTINUE = "Co&ntinue";
private const string DEFAULT_TRY_AGAIN = "&Try Again";

#endregion

#region Instance Fields
Expand Down
18 changes: 18 additions & 0 deletions Source/Krypton Components/Krypton.Toolkit/Utilities/General.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#region BSD 3-Clause License
// *****************************************************************************
// BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit)
// by Peter Wagner(aka Wagnerp) & Simon Coghlan(aka Smurf-IV), et al. 2017 - 2022. All rights reserved.
// Version 6.0.0
// *****************************************************************************
#endregion

namespace Krypton.Toolkit
{
public enum KryptonMessageBoxDefaultButton
{
Button1,
Button2,
Button3,
Button4
}
}

0 comments on commit 32350af

Please sign in to comment.