309 lines
12 KiB
C#
309 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace MessageBoxConfigurator
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
#region Version und Copyright
|
|
// Version und Copyright
|
|
string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
string copyright = GenerateCopyright();
|
|
string icon = Application.StartupPath + "\\Info.bmp";
|
|
//Assembly Datum und Zeit
|
|
static DateTime value = AssemblyDateTime();
|
|
string date = value.ToShortDateString();
|
|
string time = value.ToLongTimeString();
|
|
private static DateTime AssemblyDateTime()
|
|
{
|
|
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
|
|
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
|
|
return buildDateTime;
|
|
}
|
|
|
|
private static string CurrentYear()
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
|
|
private static string StartYear()
|
|
{
|
|
//string startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
//return startYear.Remove(0, startYear.LastIndexOf(" ") + 1);
|
|
string startYear = "";
|
|
if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © "))
|
|
{
|
|
startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", "");
|
|
while (startYear.StartsWith(" "))
|
|
{
|
|
startYear = startYear.Remove(0, 1);
|
|
}
|
|
startYear = startYear.Remove(startYear.IndexOf(" "));
|
|
return startYear;
|
|
}
|
|
else
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
}
|
|
|
|
private static string GenerateCopyright()
|
|
{
|
|
string startYear = StartYear();
|
|
string currentYear = CurrentYear();
|
|
|
|
if (startYear == currentYear)
|
|
{
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
}
|
|
else
|
|
{
|
|
//return String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", currentYear);
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Programm-Info
|
|
/// <summary>
|
|
/// Contains the name of the program file
|
|
/// </summary>
|
|
public static string ProgramName { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the version of the program file
|
|
/// </summary>
|
|
public static string ProgramVersion { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the copyright notice
|
|
/// </summary>
|
|
public static string Copyright { set; get; }
|
|
|
|
private void SetProgramInfo()
|
|
{
|
|
//Name, Version und Copyright setzen
|
|
ProgramName = programName;
|
|
ProgramVersion = programVersion;
|
|
Copyright = copyright;
|
|
}
|
|
#endregion
|
|
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
SetProgramInfo(); //Name, Version und Copyright setzen
|
|
this.Text = String.Concat(ProgramName, " - V", ProgramVersion, " - ", Copyright);
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
comboBoxResult.SelectedIndex = 0;
|
|
SelectedIcon = "None";
|
|
IntializeButtons();
|
|
}
|
|
|
|
List<MessageBoxExButton> buttons = new List<MessageBoxExButton>();
|
|
|
|
private void IntializeButtons()
|
|
{
|
|
IntializeButton("OK", "OK", "", false);
|
|
IntializeButton("Cancel", "Cancel", "", false);
|
|
IntializeButton("Yes", "Yes", "", false);
|
|
IntializeButton("No", "No", "", false);
|
|
IntializeButton("Abort", "Abort", "", false);
|
|
IntializeButton("Retry", "Retry", "", false);
|
|
IntializeButton("Ignore", "Ignore", "", false);
|
|
}
|
|
|
|
private void IntializeButton(string text, string value, string helpText, bool isCancelButton)
|
|
{
|
|
MessageBoxExButton button = new MessageBoxExButton();
|
|
button.Text = text;
|
|
button.Value = value;
|
|
button.HelpText = helpText;
|
|
button.IsCancelButton = isCancelButton;
|
|
buttons.Add(button);
|
|
}
|
|
|
|
#region MessageBox
|
|
//
|
|
#endregion
|
|
|
|
#region SaveOptions
|
|
//
|
|
#endregion
|
|
|
|
#region Timeout
|
|
//
|
|
#endregion
|
|
|
|
#region Sound
|
|
//
|
|
#endregion
|
|
|
|
#region Font
|
|
private void buttonFont_Click(object sender, EventArgs e)
|
|
{
|
|
if (fontDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
textBoxFont.Text = "\"" + fontDialog.Font.Name + "\", " + fontDialog.Font.Size.ToString().Replace(",", ".");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Icon
|
|
private string SelectedIcon { set; get; }
|
|
private void radioButtonNone_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIcon = "None";
|
|
}
|
|
|
|
private void radioButtonAsterisk_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIcon = "Asterisk";
|
|
}
|
|
|
|
private void radioButtonExclamation_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIcon = "Exclamation";
|
|
}
|
|
|
|
private void radioButtonHand_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIcon = "Hand";
|
|
}
|
|
|
|
private void radioButtonQuestion_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIcon = "Question";
|
|
}
|
|
|
|
private void radioButtonUserDefinedIcon_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
//radioButtonUserDefinedIcon.Checked =! radioButtonUserDefinedIcon.Checked;
|
|
buttonName.Enabled =! buttonName.Enabled;
|
|
textBoxIconName.Enabled =!textBoxIconName.Enabled;
|
|
}
|
|
|
|
private void buttonName_Click(object sender, EventArgs e)
|
|
{
|
|
if (openFileDialogName.ShowDialog() == DialogResult.OK)
|
|
{
|
|
textBoxIconName.Text = openFileDialogName.FileName;
|
|
}
|
|
}
|
|
|
|
private void textBoxIconName_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Button
|
|
private void buttonAddButton_Click(object sender, EventArgs e)
|
|
{
|
|
MessageBoxExButton button = new MessageBoxExButton();
|
|
button.Text = textBoxButtonText.Text;
|
|
button.Value = textBoxButtonValue.Text;
|
|
button.HelpText = textBoxButtonHelpText.Text;
|
|
button.IsCancelButton = checkBoxIsCancel.Checked;
|
|
|
|
ListViewItem item = new ListViewItem();
|
|
item.Text = button.Text;
|
|
item.Tag = button;
|
|
|
|
listViewButtons.Items.Add(item);
|
|
|
|
buttons.Add(button); //Add button to button list
|
|
}
|
|
#endregion
|
|
|
|
#region Code
|
|
private void buttonGenerateCode_Click(object sender, EventArgs e)
|
|
{
|
|
if (textBoxName.Text == "<Name>" || textBoxCaption.Text == "<Caption>" || textBoxMessage.Text == "<Text>")
|
|
{
|
|
MessageBox.Show("Please define MessageBox Values first!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
else
|
|
{
|
|
string code = String.Concat("private string OwnMessageBox()", "\r\n{"); //Method body
|
|
code = String.Concat(code, "\r\n\tMessageBoxEx msgBox = MessageBoxExManager.CreateMessageBox(\"", textBoxName.Text, "\"); //ATTENTION: Name must be unique"); //Name
|
|
code = String.Concat(code, "\r\n\t", "msgBox.Caption = \"", textBoxCaption.Text, "\";"); //Caption
|
|
code = String.Concat(code, "\r\n\t", "msgBox.Text = \"", textBoxMessage.Text, "\";"); //Message
|
|
|
|
code = String.Concat(code, "\r\n\t", "msgBox.AllowSaveResponse = ", checkBoxAllowSaveResponse.Checked.ToString().ToLower(), ";"); //Allowe Save Response
|
|
code = String.Concat(code, "\r\n\t", "msgBox.SaveResponseText = \"", textBoxSaveResponse.Text, "\";"); //Save Response Text
|
|
code = String.Concat(code, "\r\n\t", "msgBox.UseSavedResponse = ", checkBoxUseSaveResponse.Checked.ToString().ToLower(), ";"); //Use Save Response
|
|
|
|
code = String.Concat(code, "\r\n\t", "msgBox.Timeout = ", textBoxTimeout.Text, ";"); //Timeout Text
|
|
code = String.Concat(code, "\r\n\t", "msgBox.TimeoutResult = ", comboBoxResult.SelectedItem.ToString().ToLower(), ";"); //Timeout Result
|
|
|
|
code = String.Concat(code, "\r\n\t", "msgBox.PlayAlsertSound = ", checkBoxSound.Checked.ToString().ToLower(), ";"); //Play Alert Sound
|
|
|
|
code = String.Concat(code, "\r\n\t", "msgBox.Font = new Font(", textBoxFont.Text, ");"); //Font
|
|
|
|
//Icon
|
|
if (radioButtonUserDefinedIcon.Checked)
|
|
{
|
|
code = String.Concat(code, "\r\n\t", "//Use a customer icon");
|
|
code = String.Concat(code, "\r\n\t", "using (var bmp = Bitmap.FromFile(@\"", textBoxIconName.Text, "\") as Bitmap)");
|
|
code = String.Concat(code, "\r\n\t\t", "Icon = Icon.FromHandle(bmp.GetHicon());");
|
|
code = String.Concat(code, "\r\n\t", "msgBox.CustomIcon = Icon;");
|
|
}
|
|
else
|
|
{
|
|
code = String.Concat(code, "\r\n\t", "//Use a standard icon");
|
|
code = String.Concat(code, "\r\n\t", "msgBox.Icon = MessageBoxExIcon.", SelectedIcon, ";");
|
|
}
|
|
|
|
//Button
|
|
if (listViewButtons.CheckedItems.Count > 0)
|
|
{
|
|
foreach (ListViewItem item in listViewButtons.Items)
|
|
{
|
|
if (item.Checked)
|
|
{
|
|
code = String.Concat(code, "\r\n\t", "MessageBoxExButton btn", buttons[item.Index].Text, " = new MessageBoxExButton();");
|
|
code = String.Concat(code, "\r\n\t", "btn", buttons[item.Index].Text, ".Text = \"", buttons[item.Index].Text, "\";");
|
|
code = String.Concat(code, "\r\n\t", "btn", buttons[item.Index].Text, ".Value = \"", buttons[item.Index].Value, "\";");
|
|
code = String.Concat(code, "\r\n\t", "btn", buttons[item.Index].Text, ".HelpText = \"", buttons[item.Index].HelpText, "\";");
|
|
code = String.Concat(code, "\r\n\t", "btn", buttons[item.Index].Text, ".IsCancelButton = ", buttons[item.Index].IsCancelButton.ToString().ToLower(), ";");
|
|
|
|
code = String.Concat(code, "\r\n\t", "msgBox.AddButton(", "btn", buttons[item.Index].Text, ");");
|
|
}
|
|
}
|
|
}
|
|
|
|
code = String.Concat(code, "\r\n\t", "return msgBox.Show(); //Returns the result");
|
|
code = String.Concat(code, "\r\n}"); //Methode end
|
|
|
|
textBoxCode.Text = code; //Show text
|
|
}
|
|
}
|
|
|
|
private void buttonCopyToClipboard_Click(object sender, EventArgs e)
|
|
{
|
|
Clipboard.Clear(); //Clear if any old value is there in Clipboard
|
|
Clipboard.SetText(textBoxCode.Text); //Copy text to Clipboard
|
|
}
|
|
#endregion
|
|
}
|
|
}
|