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 System.Diagnostics; namespace VirtualKeyboard { public partial class QwertzKeyboard : Form { private TextBox targetTextBox; private Button okBtn; private bool isNumeric = false; private bool isCalc = false; private bool isShift = false; private Screen screen = Screen.PrimaryScreen; // Erweiterte keys auf mehr Buttons (z.B. 14 pro Reihe) private Button[][] keys = new Button[5][] { new Button[14], new Button[14], new Button[14], new Button[14], new Button[8]}; // **Echtes QWERTZ-Layout** (5 Reihen + Funktion/Steuerung) private string[] qwertzRows = { "?1234567890ß⌫↵", // Ziffernreihe "↔qwertzuiopü+", // Hauptbuchstaben 1 (versetzt) " asdfghjklöä#", // Hauptbuchstaben 2 (versetzt) "⇧ 0) targetTextBox.Text = targetTextBox.Text.Substring(0, targetTextBox.Text.Length - 1); break; default: targetTextBox.Text += btn.Text; break; } if (isShift && char.IsLetter(ch)) ch = char.ToUpper(ch); //targetTextBox.Focus(); //targetTextBox.SelectionStart = targetTextBox.Text.Length; } private void ToggleMode_Click() { isNumeric = !isNumeric; UpdateLayout(); } private void Shift_Click(object sender, EventArgs e) { Button shiftBtn = (Button)sender; isShift = !isShift; shiftBtn.BackColor = isShift ? Color.Yellow : Color.FromArgb(240, 240, 240); UpdateLayout(); } private void UpdateLayout() { if (!isNumeric) { // Zeige ALLE QWERTZ-Buttons for (int row = 0; row < qwertzRows.Length; row++) { string rowText = qwertzRows[row]; for (int col = 0; col < keys[row].Length && col < rowText.Length; col++) { char ch = rowText[col]; if (keys[row][col].Text.Length > 1) continue; keys[row][col].Text = isShift && char.IsLetter(ch) ? char.ToUpper(ch).ToString() : ch.ToString(); keys[row][col].Tag = ch; keys[row][col].Visible = true; // QWERTZ sichtbar } } } else { // **VERSTECKE ALLE QWERTZ-Buttons** und zeige nur NumPad HideAllQwertzButtons(); SetupRealNumPad(); } this.Refresh(); targetTextBox.Focus(); } private void HideAllQwertzButtons() { // Blende ALLE Keys aus (QWERTZ komplett weg) foreach (var row in keys) { foreach (var btn in row.Where(b => b != null)) { btn.Visible = false; } } } private void SetupRealNumPad() { int y = 10, xBase = 10, btnWidth = 70, btnHeight = 55, spacing = 8; if (isCalc) this.Size = new Size((btnWidth + spacing) * 4 + xBase, (btnHeight + spacing) * 5 + xBase); if (isNumeric) this.Size = new Size((btnWidth + spacing) * 3 + xBase, (btnHeight + spacing) * 4 + xBase); // NumPad-Grids füllen (erste 4 Reihen) for (int row = 0; row < numpadLayout.Length; row++) { string rowText = numpadLayout[row]; btnHeight = 55; xBase = 10; for (int col = 0; col < rowText.Length; col++) { char ch = rowText[col]; if (ch == ' ') { xBase += btnWidth + spacing; continue; } // Leerspace für breiten 0 if (ch == '↵') { Button okBtn = keys[row][col]; // OK-Button rechts unten (NumPad-Enter-Stil) okBtn.Text = "OK"; okBtn.Size = (isCalc) ? new Size(btnWidth, btnHeight * 2 + spacing) : new Size(btnWidth, btnHeight); okBtn.Location = new Point(xBase, y); okBtn.BackColor = Color.FromArgb(0, 192, 0); okBtn.ForeColor = Color.White; okBtn.Font = new Font("Arial", 14, FontStyle.Bold); okBtn.FlatStyle = FlatStyle.Flat; okBtn.FlatAppearance.BorderSize = 1; okBtn.FlatAppearance.BorderColor = Color.Green; okBtn.Visible = true; okBtn.Click += OK_Click; continue; } if (ch == '+') { btnHeight = btnHeight * 2 + spacing; } Button btn = keys[row][col]; btn.Text = ch.ToString(); btn.Tag = ch; btn.Size = (row == 4 && col == 0) ? new Size(btnWidth * 2 + spacing, btnHeight) : new Size(btnWidth, btnHeight); // Breiter 0 btn.Location = new Point(xBase, y); btn.Font = new Font("Arial", 18, FontStyle.Bold); btn.BackColor = Color.FromArgb(240, 240, 240); // NumPad-Look btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 1; btn.Visible = true; btn.Enabled = true; xBase += btn.Width + spacing; } y += (btnHeight > 55) ? (btnHeight / 2) + (spacing / 2) : btnHeight + spacing; } // Verstecke ungenutzte Keys (Reihen 4+) for (int row = 5; row < keys.Length; row++) for (int col = 0; col < keys[row].Length; col++) keys[row][col].Visible = false; } protected override void OnShown(EventArgs e) { base.OnShown(e); this.Location = new Point((screen.WorkingArea.Width - this.Width) / 2, screen.WorkingArea.Height - this.Height); } } }