- Control mit dem Tabellen bearbeitet werden können - Bei Auswahl von Elementen wird ein Event ausgelöst - Das Event behandelt dann ein Ergebnis im Hauptprogramm
505 lines
16 KiB
C#
505 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Diagnostics;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace Test_UserControl
|
|
{
|
|
//Verfügbarkeit
|
|
public enum Availability
|
|
{
|
|
Disabled,
|
|
Enabled
|
|
}
|
|
|
|
//Sichtbarkeit
|
|
public enum Visibility
|
|
{
|
|
Invisible,
|
|
Visible
|
|
}
|
|
|
|
public partial class UserControl1: UserControl
|
|
{
|
|
#region Version und Copyright
|
|
// Key und Copyright
|
|
static string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
static string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
static 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 = "";
|
|
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 ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region DLL-Info
|
|
/// <summary>
|
|
/// Contains the name of the dll file.
|
|
/// </summary>
|
|
public static string DllName { private set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the version of the dll file.
|
|
/// </summary>
|
|
public static string DllVersion { private set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the copyright notice.
|
|
/// </summary>
|
|
public static string Copyright { private set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the name-, version- and copyright-information of the dll file.
|
|
/// </summary>
|
|
public static string[] DllInfo { private set; get; }
|
|
|
|
private static void SetDllInfo()
|
|
{
|
|
//Name, Key und Copyright setzen
|
|
DllName = dllName;
|
|
DllVersion = dllVersion;
|
|
Copyright = copyright;
|
|
}
|
|
#endregion
|
|
|
|
public event EventHandler ButtonUpClick; //Der Eventhandler
|
|
public event EventHandler ButtonDownClick; //Der Eventhandler
|
|
public event EventHandler ButtonAddSeparatorClick; //Der Eventhandler
|
|
public event EventHandler CheckboxEncryptCheck; //Der Eventhandler
|
|
public event EventHandler CheckboxStandardCheck; //Der Eventhandler
|
|
|
|
/// <summary>
|
|
/// Generates a user control
|
|
/// </summary>
|
|
static UserControl1()
|
|
{
|
|
SetDllInfo(); //Name, Version und Copyright der DLL setzen
|
|
}
|
|
|
|
public UserControl1()
|
|
{
|
|
SetDllInfo(); //Name, Version und Copyright der DLL setzen
|
|
InitializeComponent();
|
|
}
|
|
|
|
public int ButtonUpAvailability { set; get; }
|
|
public int ButtonUpVisibility { set; get; }
|
|
public int ButtonDownAvailability { set; get; }
|
|
public int ButtonDownVisibility { set; get; }
|
|
public int ButtonAddSeparatorAvailability { set; get; }
|
|
public int ButtonAddSeparatorVisibility { set; get; }
|
|
private int ButtonAddSeparatorPosY { set; get; }
|
|
public int CheckBoxEncryptAvailability { set; get; }
|
|
public int CheckBoxEncryptVisibility { set; get; }
|
|
public bool CheckBoxEncryptStatusSelected { set; get; }
|
|
private int CheckBoxEncryptPosY { set; get; }
|
|
public int CheckBoxStandardAvailability { set; get; }
|
|
public int CheckBoxStandardVisibility { set; get; }
|
|
public bool CheckBoxStandardStatusSelected { set; get; }
|
|
private int CheckBoxStandardPosY { set; get; }
|
|
public int SizeX { set; get; }
|
|
public int SizeY { set; get; }
|
|
public string PressedButton { get; set; }
|
|
|
|
public void SetVisibility()
|
|
{
|
|
//Ungültige Werte korrigieren
|
|
CorrectInvalidSizeValues();
|
|
|
|
//Y-Position der Steuerelemente setzen
|
|
SetButtonAddSeparatorPositionY();
|
|
SetCheckBoxEncryptPositionY();
|
|
SetCheckBoxStandardPositionY();
|
|
|
|
//Verfügbarkeit der Steuerelemente setzen
|
|
SetButtonUpAvailability();
|
|
SetButtonAddSeparatorAvailability();
|
|
SetCheckBoxEncryptAvailability();
|
|
SetCheckBoxStandardAvailability();
|
|
SetButtonDownAvailability();
|
|
|
|
//Sichtbarkeit der Steuerelemente setzen
|
|
SetButtonUpVisibility();
|
|
SetButtonAddSeparatorVisibility();
|
|
SetCheckBoxEncryptVisibility();
|
|
SetCheckBoxStandardVisibility();
|
|
SetButtonDownVisibility();
|
|
|
|
//Die Selektion setzen
|
|
SetCheckBoxEncryptSetSelection();
|
|
SetCheckBoxStandardSetSelection();
|
|
//this.Refresh();
|
|
}
|
|
|
|
private void CorrectInvalidSizeValues()
|
|
{
|
|
if (SizeX < MinimumSize.Width)
|
|
{
|
|
SizeX = MinimumSize.Width;
|
|
}
|
|
|
|
if (SizeX > MaximumSize.Width)
|
|
{
|
|
SizeX = MaximumSize.Width;
|
|
}
|
|
|
|
if (SizeY < MinimumSize.Height)
|
|
{
|
|
SizeX = MinimumSize.Height;
|
|
}
|
|
|
|
if (SizeY > MaximumSize.Height)
|
|
{
|
|
SizeX = MaximumSize.Height;
|
|
}
|
|
}
|
|
|
|
private void SetButtonAddSeparatorPositionY()
|
|
{
|
|
if (CheckBoxEncryptAvailability == 1 & CheckBoxStandardAvailability == 1)
|
|
{
|
|
//Wenn beide Checkboxen sichtbar sind
|
|
this.buttonAddSeperator.Location = new System.Drawing.Point(0, 29 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else if (CheckBoxEncryptAvailability == 0 & CheckBoxStandardAvailability == 0)
|
|
{
|
|
//Wenn keine Checkbox sichtbar ist
|
|
this.buttonAddSeperator.Location = new System.Drawing.Point(0, 58 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else
|
|
{
|
|
//Wenn eine Checkbox sichtbar ist
|
|
this.buttonAddSeperator.Location = new System.Drawing.Point(0, 47 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxEncryptPositionY()
|
|
{
|
|
if (ButtonAddSeparatorAvailability == 1 & CheckBoxStandardAvailability == 1)
|
|
{
|
|
//Wenn der Button und eine Checkboxen sichtbar sind
|
|
this.checkBoxEncrypt.Location = new System.Drawing.Point(0, 58 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else if (ButtonAddSeparatorAvailability == 0 & CheckBoxStandardAvailability == 0)
|
|
{
|
|
//Wenn kein Button und keine Checkbox sichtbar ist
|
|
this.checkBoxEncrypt.Location = new System.Drawing.Point(0, 58 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else if (ButtonAddSeparatorAvailability == 1 & CheckBoxStandardAvailability == 0)
|
|
{
|
|
//Wenn der Button und keine Checkbox sichtbar ist
|
|
this.checkBoxEncrypt.Location = new System.Drawing.Point(0, 70 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else
|
|
{
|
|
//Wenn kein Button und eine Checkbox sichtbar ist
|
|
this.checkBoxEncrypt.Location = new System.Drawing.Point(0, 47 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxStandardPositionY()
|
|
{
|
|
if (ButtonAddSeparatorAvailability == 1 & CheckBoxEncryptAvailability == 1)
|
|
{
|
|
//Wenn der Button und eine Checkboxen sichtbar sind
|
|
this.checkBoxDefault.Location = new System.Drawing.Point(0, 81 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else if (ButtonAddSeparatorAvailability == 0 & CheckBoxEncryptAvailability == 0)
|
|
{
|
|
//Wenn kein Button und keine Checkbox sichtbar ist
|
|
this.checkBoxDefault.Location = new System.Drawing.Point(0, 58 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else if (ButtonAddSeparatorAvailability == 1 & CheckBoxEncryptAvailability == 0)
|
|
{
|
|
//Wenn der Button und keine Checkbox sichtbar ist
|
|
this.checkBoxDefault.Location = new System.Drawing.Point(0, 70 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
else
|
|
{
|
|
//Wenn kein Button und eine Checkbox sichtbar ist
|
|
this.checkBoxDefault.Location = new System.Drawing.Point(0, 47 + DiffY(MinimumSize.Height, SizeY));
|
|
}
|
|
}
|
|
|
|
private int DiffY(int minY, int currentY)
|
|
{
|
|
double diff = 0;
|
|
|
|
diff = Convert.ToDouble(currentY) - Convert.ToDouble(minY);
|
|
|
|
if (diff <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
return Convert.ToInt32(diff / 2);
|
|
}
|
|
|
|
private void SetButtonUpAvailability()
|
|
{
|
|
if (ButtonUpAvailability == 1)
|
|
{
|
|
buttonUp.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
buttonUp.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void SetButtonAddSeparatorAvailability()
|
|
{
|
|
if (ButtonAddSeparatorAvailability == 1)
|
|
{
|
|
buttonAddSeperator.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
buttonAddSeperator.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxEncryptAvailability()
|
|
{
|
|
if (CheckBoxEncryptAvailability == 1)
|
|
{
|
|
checkBoxEncrypt.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
checkBoxEncrypt.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxStandardAvailability()
|
|
{
|
|
if (CheckBoxStandardAvailability == 1)
|
|
{
|
|
checkBoxDefault.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
checkBoxDefault.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void SetButtonDownAvailability()
|
|
{
|
|
if (ButtonDownAvailability == 1)
|
|
{
|
|
buttonDown.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
buttonDown.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void SetButtonUpVisibility()
|
|
{
|
|
if (ButtonUpVisibility == 1)
|
|
{
|
|
buttonUp.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
buttonUp.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void SetButtonAddSeparatorVisibility()
|
|
{
|
|
if (ButtonAddSeparatorVisibility == 1)
|
|
{
|
|
buttonAddSeperator.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
buttonAddSeperator.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxEncryptVisibility()
|
|
{
|
|
if (CheckBoxEncryptVisibility == 1)
|
|
{
|
|
checkBoxEncrypt.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
checkBoxEncrypt.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxStandardVisibility()
|
|
{
|
|
if (CheckBoxStandardVisibility == 1)
|
|
{
|
|
checkBoxDefault.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
checkBoxDefault.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void SetButtonDownVisibility()
|
|
{
|
|
if (ButtonDownVisibility == 1)
|
|
{
|
|
buttonDown.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
buttonDown.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void SetCheckBoxEncryptSetSelection()
|
|
{
|
|
if (CheckBoxEncryptStatusSelected == true)
|
|
{
|
|
checkBoxEncrypt.Checked = true; //CheckBox ist selektiert
|
|
}
|
|
else
|
|
{
|
|
checkBoxEncrypt.Checked = false; //CheckBox ist deselektiert
|
|
CheckBoxEncryptStatusSelected = false; //Zur Sicherheit auf einen definierten Wert setzen
|
|
}
|
|
checkBoxEncrypt.Refresh();
|
|
}
|
|
|
|
private void SetCheckBoxStandardSetSelection()
|
|
{
|
|
if (CheckBoxStandardStatusSelected == true)
|
|
{
|
|
checkBoxDefault.Checked = true; //CheckBox ist selektiert
|
|
}
|
|
else
|
|
{
|
|
checkBoxDefault.Checked = false; //CheckBox ist deselektiert
|
|
CheckBoxStandardStatusSelected = false; //Zur Sicherheit auf einen definierten Wert setzen
|
|
}
|
|
}
|
|
|
|
private void buttonUp_Click(object sender, EventArgs e)
|
|
{
|
|
OnButtonUpClick();
|
|
}
|
|
|
|
private void buttonDown_Click(object sender, EventArgs e)
|
|
{
|
|
OnButtonDownClick();
|
|
}
|
|
|
|
private void buttonAddSeperator_Click(object sender, EventArgs e)
|
|
{
|
|
OnButtonAddSeparatorClick();
|
|
}
|
|
|
|
private void checkBoxEncrypt_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
OnCheckboxEncryptCheck(); //Ereignis ausführen
|
|
|
|
//Checkbox Status setzen
|
|
CheckBoxEncryptStatusSelected = checkBoxEncrypt.Checked;
|
|
}
|
|
|
|
private void checkBoxDefault_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
OnCheckboxStandardCheck(); //Ereignis ausführen
|
|
|
|
//Checkbox Status setzen
|
|
CheckBoxStandardStatusSelected = checkBoxDefault.Checked;
|
|
}
|
|
|
|
protected void OnButtonUpClick()
|
|
{
|
|
//Registrierte Ereignisbehandlungsmethode ausführen
|
|
ButtonUpClick?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
protected void OnButtonDownClick()
|
|
{
|
|
//Registrierte Ereignisbehandlungsmethode ausführen
|
|
ButtonDownClick?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
protected void OnButtonAddSeparatorClick()
|
|
{
|
|
//Registrierte Ereignisbehandlungsmethode ausführen
|
|
ButtonAddSeparatorClick?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
protected void OnCheckboxEncryptCheck()
|
|
{
|
|
//Registrierte Ereignisbehandlungsmethode ausführen
|
|
CheckboxEncryptCheck?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
protected void OnCheckboxStandardCheck()
|
|
{
|
|
//Registrierte Ereignisbehandlungsmethode ausführen
|
|
CheckboxStandardCheck?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|