Programm_Wirl/AA-Forms/CustomInputBox.cs

91 lines
2.4 KiB
C#

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();
}
public CustomInputBox(string Frage, string Title, string Eingabe, string numeric) : this()
{
if (numeric == "isNumeric") 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;
}
private void TextBoxText_Click(object sender, EventArgs e)
{
this.textBoxText.Clear();
if (TouchHelper.IsTouchDeviceReady())
{
if (keyboard == null || keyboard.IsDisposed)
{
keyboard = new QwertzKeyboard(textBoxText, "isNumeric");
keyboard.Show();
}
else
{
keyboard.Close();
keyboard = new QwertzKeyboard(textBoxText, "isNumeric");
keyboard.Show();
}
}
}
private void TextBoxText_Enter(object sender, EventArgs e)
{
this.textBoxText.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.SelectAll();
}
}
}
}
}