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 = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; 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; } #endregion #region Programm-Info /// /// Contains the name of the program file /// public static string ProgramName { set; get; } /// /// Contains the version of the program file /// public static string ProgramVersion { set; get; } /// /// Contains the copyright notice /// public static string Copyright { set; get; } private void SetProgramInfo() { //Name, Version und Copyright setzen ProgramName = programName; ProgramVersion = programVersion; Copyright = copyright; } #endregion /// /// Set or Get the pressed button text /// 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 } }