Updates for adding custom buttons
This commit is contained in:
parent
db4f114caf
commit
2ffab17caf
@ -241,6 +241,21 @@ namespace JR.Utils.GUI.Forms
|
|||||||
return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton);
|
return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the specified message box.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner">The owner.</param>
|
||||||
|
/// <param name="text">The text.</param>
|
||||||
|
/// <param name="caption">The caption.</param>
|
||||||
|
/// <param name="buttons">The buttons.</param>
|
||||||
|
/// <param name="icon">The icon.</param>
|
||||||
|
/// <param name="defaultButton">The default button.</param>
|
||||||
|
/// <returns>The dialog result.</returns>
|
||||||
|
public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
||||||
|
{
|
||||||
|
return FlexibleMessageBoxForm.ShowCustom(null, text, caption, buttons, icon);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal form class
|
#region Internal form class
|
||||||
@ -420,15 +435,15 @@ namespace JR.Utils.GUI.Forms
|
|||||||
private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " ";
|
private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " ";
|
||||||
|
|
||||||
//These are the possible buttons (in a standard MessageBox)
|
//These are the possible buttons (in a standard MessageBox)
|
||||||
private enum ButtonID { OK = 0, CANCEL, YES, NO, ABORT, RETRY, IGNORE };
|
private enum ButtonID { OK = 0, CANCEL, YES, NO, ABORT, RETRY, IGNORE, OVERWRITE, RENAME };
|
||||||
|
|
||||||
//These are the buttons texts for different languages.
|
//These are the buttons texts for different languages.
|
||||||
//If you want to add a new language, add it here and in the GetButtonText-Function
|
//If you want to add a new language, add it here and in the GetButtonText-Function
|
||||||
private enum TwoLetterISOLanguageID { en, de, es, it };
|
private enum TwoLetterISOLanguageID { en, de, es, it };
|
||||||
private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore" }; //Note: This is also the fallback language
|
private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore", "&Overwrite", "&Rename" }; //Note: This is also the fallback language
|
||||||
private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren" };
|
private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren", "&Overwrite", "&Rename" };
|
||||||
private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar" };
|
private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar", "&Overwrite", "&Rename" };
|
||||||
private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora" };
|
private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora", "&Overwrite", "&Rename" };
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -694,6 +709,7 @@ namespace JR.Utils.GUI.Forms
|
|||||||
flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
|
flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case MessageBoxButtons.OK:
|
case MessageBoxButtons.OK:
|
||||||
default:
|
default:
|
||||||
flexibleMessageBoxForm.visibleButtonsCount = 1;
|
flexibleMessageBoxForm.visibleButtonsCount = 1;
|
||||||
@ -709,16 +725,38 @@ namespace JR.Utils.GUI.Forms
|
|||||||
flexibleMessageBoxForm.defaultButton = defaultButton;
|
flexibleMessageBoxForm.defaultButton = defaultButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
private static void SetDialogButtonsCustom(FlexibleMessageBoxForm flexibleMessageBoxForm)
|
||||||
|
{
|
||||||
|
flexibleMessageBoxForm.visibleButtonsCount = 3;
|
||||||
|
|
||||||
#region Private event handlers
|
flexibleMessageBoxForm.button1.Visible = true;
|
||||||
|
flexibleMessageBoxForm.button1.Text = flexibleMessageBoxForm.GetButtonText(ButtonID.CANCEL);
|
||||||
|
flexibleMessageBoxForm.button1.DialogResult = DialogResult.Abort;
|
||||||
|
|
||||||
/// <summary>
|
flexibleMessageBoxForm.button2.Visible = true;
|
||||||
/// Handles the Shown event of the FlexibleMessageBoxForm control.
|
flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(ButtonID.OVERWRITE);
|
||||||
/// </summary>
|
flexibleMessageBoxForm.button2.DialogResult = DialogResult.Retry;
|
||||||
/// <param name="sender">The source of the event.</param>
|
|
||||||
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
|
flexibleMessageBoxForm.button3.Visible = true;
|
||||||
private void FlexibleMessageBoxForm_Shown(object sender, EventArgs e)
|
flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(ButtonID.RENAME);
|
||||||
|
flexibleMessageBoxForm.button3.DialogResult = DialogResult.Ignore;
|
||||||
|
|
||||||
|
flexibleMessageBoxForm.ControlBox = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private event handlers
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles the Shown event of the FlexibleMessageBoxForm control.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The source of the event.</param>
|
||||||
|
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
|
||||||
|
private void FlexibleMessageBoxForm_Shown(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int buttonIndexToFocus = 1;
|
int buttonIndexToFocus = 1;
|
||||||
Button buttonToFocus;
|
Button buttonToFocus;
|
||||||
@ -866,6 +904,46 @@ namespace JR.Utils.GUI.Forms
|
|||||||
return flexibleMessageBoxForm.ShowDialog(owner);
|
return flexibleMessageBoxForm.ShowDialog(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the specified message box.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner">The owner.</param>
|
||||||
|
/// <param name="text">The text.</param>
|
||||||
|
/// <param name="caption">The caption.</param>
|
||||||
|
/// <param name="buttons">The buttons.</param>
|
||||||
|
/// <param name="icon">The icon.</param>
|
||||||
|
/// <param name="defaultButton">The default button.</param>
|
||||||
|
/// <returns>The dialog result.</returns>
|
||||||
|
public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
||||||
|
{
|
||||||
|
//Create a new instance of the FlexibleMessageBox form
|
||||||
|
var flexibleMessageBoxForm = new FlexibleMessageBoxForm();
|
||||||
|
flexibleMessageBoxForm.ShowInTaskbar = false;
|
||||||
|
|
||||||
|
//Bind the caption and the message text
|
||||||
|
flexibleMessageBoxForm.CaptionText = caption;
|
||||||
|
flexibleMessageBoxForm.MessageText = text;
|
||||||
|
flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm;
|
||||||
|
|
||||||
|
//Set the buttons visibilities and texts. Also set a default button.
|
||||||
|
SetDialogButtonsCustom(flexibleMessageBoxForm);
|
||||||
|
|
||||||
|
//Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
|
||||||
|
SetDialogIcon(flexibleMessageBoxForm, icon);
|
||||||
|
|
||||||
|
//Set the font for all controls
|
||||||
|
flexibleMessageBoxForm.Font = FONT;
|
||||||
|
flexibleMessageBoxForm.richTextBoxMessage.Font = FONT;
|
||||||
|
|
||||||
|
//Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
|
||||||
|
SetDialogSizes(flexibleMessageBoxForm, text, caption);
|
||||||
|
|
||||||
|
//Set the dialogs start position when given. Otherwise center the dialog on the current screen.
|
||||||
|
SetDialogStartPosition(flexibleMessageBoxForm, owner);
|
||||||
|
//Show the dialog
|
||||||
|
return flexibleMessageBoxForm.ShowDialog(owner);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
} //class FlexibleMessageBoxForm
|
} //class FlexibleMessageBoxForm
|
||||||
|
|
||||||
|
@ -228,13 +228,23 @@ namespace VEPROMS
|
|||||||
else if (MyProcedure != null)
|
else if (MyProcedure != null)
|
||||||
{
|
{
|
||||||
var fileLocation = txtExport.Text;
|
var fileLocation = txtExport.Text;
|
||||||
|
|
||||||
if (File.Exists(fileLocation))
|
if (File.Exists(fileLocation))
|
||||||
{ // C2022-029 if an existing export of the same name is found, provide option to overwrite it
|
{ // C2022-029 if an existing export of the same name is found, provide option to overwrite it
|
||||||
DialogResult ovewriteEx = FlexibleMessageBox.Show("There is already another export file with the same name, would you like to overwrite it?\r\n\r\nSelecting 'Cancel' will cancel the export.", "Overwrite the export change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);// == DialogResult.Yes;
|
DialogResult ovewriteEx = FlexibleMessageBox.ShowCustom(null, "There is already another export file with the same name, you can either overwrite the existing file, or have the existing file renamed with it's created date appended?\r\n\r\nSelecting 'Cancel' will cancel the export.", "What would you like to do?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);// == DialogResult.Yes;
|
||||||
|
|
||||||
if (ovewriteEx == DialogResult.Cancel) btnCloseExport.Enabled = true;
|
if (ovewriteEx == DialogResult.Abort) btnCloseExport.Enabled = true;
|
||||||
else
|
else if (ovewriteEx == DialogResult.Retry)
|
||||||
|
{
|
||||||
|
// Ovewrite
|
||||||
|
// Extract directory, filename, and extension
|
||||||
|
string directory = Path.GetDirectoryName(fileLocation);
|
||||||
|
string filename = Path.GetFileNameWithoutExtension(fileLocation);
|
||||||
|
string extension = Path.GetExtension(fileLocation);
|
||||||
|
|
||||||
|
fileLocation = $"{directory}\\{filename}{extension}";
|
||||||
|
msg = "The export file has been overwritten. ";
|
||||||
|
}
|
||||||
|
else if (ovewriteEx == DialogResult.Ignore)
|
||||||
{
|
{
|
||||||
// Extract directory, filename, and extension
|
// Extract directory, filename, and extension
|
||||||
string directory = Path.GetDirectoryName(fileLocation);
|
string directory = Path.GetDirectoryName(fileLocation);
|
||||||
@ -242,8 +252,18 @@ namespace VEPROMS
|
|||||||
string extension = Path.GetExtension(fileLocation);
|
string extension = Path.GetExtension(fileLocation);
|
||||||
|
|
||||||
// Generate the new filename with a datestamp
|
// Generate the new filename with a datestamp
|
||||||
string datestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
|
fileLocation = $"{directory}\\{filename}{extension}";
|
||||||
fileLocation = $"{directory}\\{filename}_{datestamp}{extension}";
|
|
||||||
|
// Get the creation date of the existing file
|
||||||
|
DateTime creationDate = File.GetCreationTime(fileLocation);
|
||||||
|
|
||||||
|
// Format the creation date to use it as a datestamp
|
||||||
|
string datestamp = creationDate.ToString("yyyyMMddHHmmss");
|
||||||
|
|
||||||
|
string newFileLocation = $"{directory}\\{filename}_{datestamp}{extension}";
|
||||||
|
|
||||||
|
File.Move(fileLocation, newFileLocation);
|
||||||
|
msg = "The previous export has been renamed, the export file has been created. ";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -734,7 +754,7 @@ namespace VEPROMS
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
FlexibleMessageBox.Show("The import failed, check the error log for more information.", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
FlexibleMessageBox.Show(null, "The import failed, check the error log for more information.", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
_MyLog.Warn("Failure During Import", ex);
|
_MyLog.Warn("Failure During Import", ex);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user