136 lines
4.1 KiB
C#
136 lines
4.1 KiB
C#
using Deckungsbeitrag.AA_Klassen;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
using VirtualKeyboard;
|
|
|
|
namespace Deckungsbeitrag.AA_Forms
|
|
{
|
|
public partial class CustomMessageBox : Form
|
|
{
|
|
public DialogResult result;
|
|
public string buttontext;
|
|
private string title;
|
|
private string caption;
|
|
private string todo;
|
|
private string[] buttons;
|
|
|
|
private static string Title;
|
|
private static string Caption;
|
|
private static string Todo;
|
|
private static string[] Buttons;
|
|
|
|
public CustomMessageBox(string title, string caption, string todo, string[] buttons)
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
this.title = title;
|
|
this.caption = caption;
|
|
this.todo = todo;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Aufrufen der CustomMessageBox.
|
|
/// </summary>
|
|
/// <param name="title">FormTitel</param>
|
|
/// <param name="caption">Message-Text</param>
|
|
/// <param name="todo">ToDo</param>
|
|
/// <param name="buttons">Welche Buttonnamen [0]=Button OK, [1]=Button Abbrechen, [2]=Button Alternative</param>
|
|
public static DialogResult Show(string title, string caption, string todo, string[] buttons)
|
|
{
|
|
CustomMessageBox messageBox = new CustomMessageBox(title, caption, todo, buttons);
|
|
return messageBox.ShowDialog();
|
|
}
|
|
|
|
private void CustomMessageBox_Load(object sender, EventArgs e)
|
|
{
|
|
GetTranslation(title, caption, todo);
|
|
Buttons = buttons;
|
|
|
|
this.labelText.Text = Caption;
|
|
this.Text = Title;
|
|
if (Todo == null)
|
|
{
|
|
this.labelToDo.Visible = false;
|
|
}
|
|
else this.labelToDo.Text = Todo;
|
|
|
|
GetButtons();
|
|
}
|
|
private void GetButtons()
|
|
{
|
|
if (Buttons.Length == 1)
|
|
{
|
|
this.buttonAbbrechen.Visible = false;
|
|
this.buttonOK.Text = TranslationService.T($"Button.{Buttons[0]}");
|
|
this.buttonOK.AccessibleName = Buttons[0];
|
|
}
|
|
if (Buttons.Length == 2)
|
|
{
|
|
this.buttonAbbrechen.Visible = true;
|
|
this.buttonOK.Text = TranslationService.T($"Button.{Buttons[0]}");
|
|
this.buttonAbbrechen.Text = TranslationService.T($"button.{Buttons[1]}");
|
|
this.buttonOK.AccessibleName = Buttons[0];
|
|
this.buttonAbbrechen.AccessibleName = Buttons[1];
|
|
}
|
|
if (Buttons.Length == 3)
|
|
{
|
|
this.buttonAlternativ.Visible = true;
|
|
this.buttonOK.Text = TranslationService.T($"Button.{Buttons[0]}");
|
|
this.buttonAbbrechen.Text = TranslationService.T($"Button.{Buttons[1]}");
|
|
this.buttonAlternativ.Text = TranslationService.T($"Button.{Buttons[2]}");
|
|
this.buttonOK.AccessibleName = Buttons[0];
|
|
this.buttonAbbrechen.AccessibleName = Buttons[1];
|
|
this.buttonAlternativ.AccessibleName = Buttons[2];
|
|
}
|
|
}
|
|
private static void GetTranslation(string title, string caption, string todo)
|
|
{
|
|
Title = TranslationService.T(title);
|
|
Caption = TranslationService.T(caption);
|
|
Todo = TranslationService.T(todo);
|
|
}
|
|
|
|
private void Button_Click(object sender, EventArgs e)
|
|
{
|
|
Button btn = sender as Button;
|
|
|
|
switch (btn.AccessibleName.ToLower())
|
|
{
|
|
case var t when t == "ok": this.DialogResult = DialogResult.OK; break;
|
|
case var t when t == "ja": this.DialogResult = DialogResult.Yes; break;
|
|
case var t when t == "abbrechen": this.DialogResult = DialogResult.Cancel; break;
|
|
case var t when t == "nein": this.DialogResult = DialogResult.No; break;
|
|
default:
|
|
this.buttontext = btn.AccessibleName;
|
|
this.DialogResult = DialogResult.Ignore;
|
|
break;
|
|
}
|
|
|
|
this.Close();
|
|
}
|
|
|
|
protected override bool ProcessDialogKey(Keys keyData)
|
|
{
|
|
// Taste T löst Übersetzung aus.
|
|
if (Form.ModifierKeys == Keys.None && keyData == Keys.T)
|
|
{
|
|
this.Close();
|
|
return true;
|
|
}
|
|
|
|
return base.ProcessDialogKey(keyData);
|
|
}
|
|
|
|
}
|
|
}
|