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 readonly string frage; //private readonly string title; //private readonly string eingabe; public string text; public CustomInputBox() { InitializeComponent(); ControlBox = false; } public CustomInputBox(string Frage, string Title, string Eingabe, string numeric) : this() { 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; } this.labelFrage.Text = Frage; this.labelEingabe.Text = Eingabe + ":"; this.Text = Title; if (isNumeric) this.textBoxText.Text = "1"; else this.textBoxText.Text = string.Empty; this.buttonOK.Text = TranslationService.T("Button.Ok"); this.buttonAbbrechen.Text = TranslationService.T("Button.Abbrechen"); } 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 { MessageBox.Show("Bitte nur ganze Zahlen eingeben.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; this.textBoxText.Clear(); } } else { this.text = textBoxText.Text; } } } }