using Deckungsbeitrag.AA_Klassen; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using VirtualKeyboard; namespace Deckungsbeitrag.AA_Forms { public partial class CustomInputBox : Form { private QwertzKeyboard keyboard; private readonly bool isNumeric; private bool isFallback = false; private string title; private string caption; private string todo; private string eingabe; private string numeric; public string text; private static string Title; private static string Caption; private static string Todo; private static string Eingabe; public CustomInputBox(string numeric) { InitializeComponent(); ControlBox = false; if (numeric == "isNumeric") { this.textBoxText.AccessibleName = "isNumeric"; this.isNumeric = true; } if (numeric == "isAlpha") { this.textBoxText.AccessibleName = "isAlpha"; this.isNumeric = false; } if (numeric == "isCalc") { this.textBoxText.AccessibleName = "isClac"; this.isNumeric = true; } } public CustomInputBox(string frage, string title, string eingabe, string numeric) : this(numeric) { Caption = frage; Eingabe = eingabe; Title = title; } /// /// Aufrufen der CustomInputBox. Besser .Show verwenden. /// /// Key von BoxTitel /// Key von Message-Text /// Key von ToDo /// Hinweis welche Eingabe erwartet wird /// Eingabeformat für VirtuelKeyboard (isNumeric, isCalc oder isAlpha) public CustomInputBox(string title, string caption, string todo, string eingabe, string Numeric) : this(Numeric) { this.title = title; this.caption = caption; this.todo = todo; this.eingabe = eingabe; } /// /// Aufrufen der CustomInputBox. /// /// Key von BoxTitel /// Key von Message-Text /// Key von ToDo /// Hinweis welche Eingabe erwartet wird /// Eingabeformat für VirtuelKeyboard (isNumeric, isCalc oder isAlpha) public static DialogResult Show(string title, string caption, string todo, string eingabe, string numeric) { CustomInputBox inputBox = new CustomInputBox(title, caption, todo, eingabe, numeric); return inputBox.ShowDialog(); } private void CustomInputBox_Load(object sender, EventArgs e) { GetTranslation(title, caption, todo, eingabe); this.buttonOK.Text = TranslationService.T("Button.Ok"); this.buttonAbbrechen.Text = TranslationService.T("Button.Abbrechen"); this.Text = Title; this.labelFrage.Text = Caption + " "; this.labelFrage.Text += !string.IsNullOrWhiteSpace(Todo) ? Todo : string.Empty; this.labelEingabe.Text = !string.IsNullOrWhiteSpace(Eingabe) ? Eingabe + ":" : string.Empty; if (isNumeric) this.textBoxText.Text = "1"; else this.textBoxText.Text = string.Empty; } /// /// Die strings werden aus der translation.json ausgelesen und übersetzt. /// /// /// /// /// private static void GetTranslation(string title, string caption, string todo, string eingabe) { if (title != null) Title = TranslationService.T(title); if (caption != null) Caption = TranslationService.T(caption); if (todo != null) Todo = TranslationService.T(todo); if (eingabe != null) Eingabe = TranslationService.T(eingabe); } private void TextBoxText_Click(object sender, EventArgs e) { TextBox tb = (TextBox)sender; tb.Clear(); keyboard = Funktionen.OpenVirtualKeyboard(sender); } private void TextBoxText_Enter(object sender, EventArgs e) { TextBox tb = (TextBox)sender; keyboard = Funktionen.OpenVirtualKeyboard(sender); this.BeginInvoke(new Action(() => { if (!tb.IsDisposed && tb.CanFocus) { tb.Focus(); tb.SelectAll(); } })); } private void ButtonAbbrechen_Click(object sender, EventArgs e) { if (keyboard != null) keyboard.Close(); this.DialogResult = DialogResult.Cancel; this.Close(); } private void ButtonOK_Click(object sender, EventArgs e) { if (keyboard != null) keyboard.Close(); this.DialogResult = DialogResult.OK; this.Close(); } private void TextBoxText_Validating(object sender, CancelEventArgs e) { if (buttonAbbrechen.Focused) return; if (isNumeric) { if (int.TryParse(textBoxText.Text, out int value)) this.text = textBoxText.Text; else { CustomMessageBox.Show("Titel.Fehler", "Text.Fehler.NurZahlen", null, new string[] { "Ok" }); e.Cancel = true; this.textBoxText.Clear(); } } else { this.text = textBoxText.Text; } } /// /// Tastendruck wird erkannt und verarbeitet. /// /// /// protected override bool ProcessDialogKey(Keys keyData) { // Taste T löst Übersetzung in FallbackLanguage aus bzw. setzt die Übersetzung wieder auf CurrentLanguage zurück. if (Form.ModifierKeys == Keys.None && keyData == Keys.T) { if (!isFallback) TranslationService.SetLanguage(TranslationService.FallbackLanguage); else TranslationService.SetLanguage(Program._settings.Culture); isFallback = !isFallback; CustomInputBox_Load(this, null); return true; } return base.ProcessDialogKey(keyData); } } }