ownmessagebox_projects_visu.../OwnMessageBox/OwnMessageBox.cs
2020-11-26 12:04:08 +01:00

482 lines
19 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 EOwnMessageBox
{
public partial class OwnMessageBox : 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
/// <summary>
/// Set or Get the pressed button text
/// </summary>
public string Result { set; get; }
public OwnMessageBox()
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
}
public OwnMessageBox(Window.Size size)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = "";
HideButton("Left");
HideButton("Center");
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, string lblText)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
this.labelText.Text = lblText;
HideButton("Left");
HideButton("Center");
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, string lblText, string btnCenter)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
this.labelText.Text = lblText;
HideButton("Left");
this.buttonCenter.Text = btnCenter;
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, string lblText, string btnLeft, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
HideButton("Center");
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, string lblText, string btnLeft, string btnCenter, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
this.buttonCenter.Text = btnCenter;
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, Window.ControlBox ctrlBox, string lblText, string btnCenter)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (ctrlBox == Window.ControlBox.Off)
{
this.ControlBox = false;
}
HideButton("Left");
this.buttonCenter.Text = btnCenter;
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, Window.ControlBox ctrlBox, string lblText, string btnLeft, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (ctrlBox == Window.ControlBox.Off)
{
this.ControlBox = false;
}
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
HideButton("Center");
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, Window.ControlBox ctrlBox, string lblText, string btnLeft, string btnCenter, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (ctrlBox == Window.ControlBox.Off)
{
this.ControlBox = false;
}
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
this.buttonCenter.Text = btnCenter;
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, Icons.Icon icon, string lblText)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
this.labelText.Text = lblText;
HideButton("Left");
HideButton("Center");
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, Icons.Icon icon, string lblText, string btnCenter)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
this.labelText.Text = lblText;
HideButton("Left");
this.buttonCenter.Text = btnCenter;
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, Icons.Icon icon, string lblText, string btnLeft, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
HideButton("Center");
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, Icons.Icon icon, string lblText, string btnLeft, string btnCenter, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
this.buttonCenter.Text = btnCenter;
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, Window.ControlBox ctrlBox, Icons.Icon icon, string lblText, string btnCenter)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (ctrlBox == Window.ControlBox.Off)
{
this.ControlBox = false;
}
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
HideButton("Left");
this.buttonCenter.Text = btnCenter;
HideButton("Right");
}
public OwnMessageBox(Window.Size size, string name, Window.ControlBox ctrlBox, Icons.Icon icon, string lblText, string btnLeft, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (ctrlBox == Window.ControlBox.Off)
{
this.ControlBox = false;
}
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
HideButton("Center");
this.buttonRight.Text = btnRight;
}
public OwnMessageBox(Window.Size size, string name, Window.ControlBox ctrlBox, Icons.Icon icon, string lblText, string btnLeft, string btnCenter, string btnRight)
{
SetProgramInfo(); //Name, Version und Copyright setzen
InitializeComponent();
this.MinimumSize = new System.Drawing.Size(Window.XSize(Window.Size.Nano), Window.YSize(Window.Size.Nano));
this.ClientSize = new System.Drawing.Size(Window.XSize(size), Window.YSize(size));
this.Text = name;
if (ctrlBox == Window.ControlBox.Off)
{
this.ControlBox = false;
}
if (icon != Icons.Icon.NoIcon)
{
DrawIcon(icon);
ResizeLabel();
}
this.labelText.Text = lblText;
this.buttonLeft.Text = btnLeft;
this.buttonCenter.Text = btnCenter;
this.buttonRight.Text = btnRight;
}
private System.Drawing.Image SetIcon(Icons.Icon icon)
{
this.pictureBoxIcon.BackgroundImage = global::OwnMessageBox.Properties.Resources.Information;
System.Drawing.Image image = null;
switch (icon)
{
case Icons.Icon.Construction:
image = global::OwnMessageBox.Properties.Resources.Construction;
break;
case Icons.Icon.Email:
image = global::OwnMessageBox.Properties.Resources.Email;
break;
case Icons.Icon.Error:
image = global::OwnMessageBox.Properties.Resources.Error;
break;
case Icons.Icon.FatalError:
image = global::OwnMessageBox.Properties.Resources.FatalError;
break;
case Icons.Icon.Instruction:
image = global::OwnMessageBox.Properties.Resources.Instruction;
break;
case Icons.Icon.Question:
image = global::OwnMessageBox.Properties.Resources.Question;
break;
case Icons.Icon.Telephon:
image = global::OwnMessageBox.Properties.Resources.Telephone;
break;
case Icons.Icon.Tips:
image = global::OwnMessageBox.Properties.Resources.Tips;
break;
case Icons.Icon.Warning:
image = global::OwnMessageBox.Properties.Resources.Warning;
break;
default:
image = global::OwnMessageBox.Properties.Resources.Information;
break;
}
return image;
}
private void DrawIcon(Icons.Icon icon)
{
this.pictureBoxIcon.BackgroundImage = SetIcon(icon);
this.pictureBoxIcon.Enabled = true;
this.pictureBoxIcon.Visible = true;
}
private void ResizeLabel()
{
this.labelText.Size = new System.Drawing.Size(this.labelText.Size.Width - 50, 399);
this.labelText.Location = new System.Drawing.Point(63, 13);
}
private void HideButton(string pos)
{
switch (pos.ToLower())
{
case "left":
this.buttonLeft.Enabled = false;
this.buttonLeft.Visible = false;
break;
case "center":
this.buttonCenter.Enabled = false;
this.buttonCenter.Visible = false;
break;
case "right":
this.buttonRight.Enabled = false;
this.buttonRight.Visible = false;
break;
}
}
#region Button
private void buttonLeft_Click(object sender, EventArgs e)
{
//Den Text des Button zurückgeben
Result = sender.ToString().Remove(0, sender.ToString().LastIndexOf(":") + 2);
Close();
}
private void buttonCenter_Click(object sender, EventArgs e)
{
//Den Text des Button zurückgeben
Result = sender.ToString().Remove(0, sender.ToString().LastIndexOf(":") + 2);
Close();
}
private void buttonRight_Click(object sender, EventArgs e)
{
//Den Text des Button zurückgeben
Result = sender.ToString().Remove(0, sender.ToString().LastIndexOf(":") + 2);
Close();
}
#endregion
}
}