diff --git a/T9KeyboardApp/AddTextButton.cs b/T9KeyboardApp/AddTextButton.cs new file mode 100644 index 0000000..b35243b --- /dev/null +++ b/T9KeyboardApp/AddTextButton.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace T9KeyboardApp +{ + public class AddTextButton : Button + { + private static int x = -1; + private static readonly int numPerRow = 7; + private readonly TextBox tetheredBox; + private readonly String appliedText; + private readonly Point topPosition = new(462, 493); + private static readonly Point step = new(84, 46); + + public AddTextButton(TextBox target, String text) + { + x++; + Location = new Point( + topPosition.X + (x % numPerRow) * step.X, + topPosition.Y + (x / numPerRow) * step.Y + ); + + tetheredBox = target; + appliedText = text; + Text = appliedText; + Click += AddText; + BackColor = Color.Silver; + UseVisualStyleBackColor = true; + FlatAppearance.BorderColor = Color.Gray; + FlatAppearance.BorderSize = 2; + FlatAppearance.MouseDownBackColor = Color.FromArgb(224, 224, 224); + + Size = new Size(78, 38); + FlatStyle = FlatStyle.Flat; + } + + private void AddText(object? sender, EventArgs e) + { + tetheredBox.Text += appliedText; + tetheredBox.Select(); + } + } +} diff --git a/T9KeyboardApp/Form1.Designer.cs b/T9KeyboardApp/Form1.Designer.cs index b7aae74..99797c7 100644 --- a/T9KeyboardApp/Form1.Designer.cs +++ b/T9KeyboardApp/Form1.Designer.cs @@ -50,6 +50,11 @@ private void InitializeComponent() lblEntryMode = new Label(); label1 = new Label(); lblActiveChar = new Label(); + btnMFG = new Button(); + btnSGDH = new Button(); + btnAnrede = new Button(); + btnHello = new Button(); + btnGruss = new Button(); SuspendLayout(); // // textBox1 @@ -65,7 +70,7 @@ private void InitializeComponent() textBox1.Multiline = true; textBox1.Name = "textBox1"; textBox1.ReadOnly = true; - textBox1.Size = new Size(758, 583); + textBox1.Size = new Size(758, 460); textBox1.TabIndex = 0; textBox1.KeyPress += Form1_KeyPress; textBox1.KeyUp += Form1_KeyUp; @@ -309,6 +314,7 @@ private void InitializeComponent() lblEntryMode.Size = new Size(117, 36); lblEntryMode.TabIndex = 17; lblEntryMode.Text = "Abc"; + lblEntryMode.UseMnemonic = false; // // label1 // @@ -329,6 +335,72 @@ private void InitializeComponent() lblActiveChar.Size = new Size(69, 36); lblActiveChar.TabIndex = 19; lblActiveChar.Text = "x"; + lblActiveChar.UseMnemonic = false; + // + // btnMFG + // + btnMFG.BackColor = Color.NavajoWhite; + btnMFG.FlatAppearance.BorderColor = Color.Gray; + btnMFG.FlatAppearance.BorderSize = 2; + btnMFG.Location = new Point(1140, 493); + btnMFG.Name = "btnMFG"; + btnMFG.Size = new Size(78, 38); + btnMFG.TabIndex = 23; + btnMFG.Text = "MFG"; + btnMFG.UseVisualStyleBackColor = false; + btnMFG.Click += Button_MFG_Click; + // + // btnSGDH + // + btnSGDH.BackColor = Color.NavajoWhite; + btnSGDH.FlatAppearance.BorderColor = Color.Gray; + btnSGDH.FlatAppearance.BorderSize = 2; + btnSGDH.Location = new Point(1056, 493); + btnSGDH.Name = "btnSGDH"; + btnSGDH.Size = new Size(78, 38); + btnSGDH.TabIndex = 24; + btnSGDH.Text = "SGDH"; + btnSGDH.UseVisualStyleBackColor = false; + btnSGDH.Click += BtnSGDH_Click; + // + // btnAnrede + // + btnAnrede.BackColor = Color.NavajoWhite; + btnAnrede.FlatAppearance.BorderColor = Color.Gray; + btnAnrede.FlatAppearance.BorderSize = 2; + btnAnrede.Location = new Point(1056, 537); + btnAnrede.Name = "btnAnrede"; + btnAnrede.Size = new Size(78, 38); + btnAnrede.TabIndex = 25; + btnAnrede.Text = "Liebe"; + btnAnrede.UseVisualStyleBackColor = false; + btnAnrede.Click += BtnAnrede_Click; + // + // btnHello + // + btnHello.BackColor = Color.NavajoWhite; + btnHello.FlatAppearance.BorderColor = Color.Gray; + btnHello.FlatAppearance.BorderSize = 2; + btnHello.Location = new Point(972, 537); + btnHello.Name = "btnHello"; + btnHello.Size = new Size(78, 38); + btnHello.TabIndex = 26; + btnHello.Text = "Hallo"; + btnHello.UseVisualStyleBackColor = false; + btnHello.Click += BtnHello_Click; + // + // btnGruss + // + btnGruss.BackColor = Color.NavajoWhite; + btnGruss.FlatAppearance.BorderColor = Color.Gray; + btnGruss.FlatAppearance.BorderSize = 2; + btnGruss.Location = new Point(1140, 537); + btnGruss.Name = "btnGruss"; + btnGruss.Size = new Size(78, 38); + btnGruss.TabIndex = 27; + btnGruss.Text = "Herzl."; + btnGruss.UseVisualStyleBackColor = false; + btnGruss.Click += BtnGruss_Click; // // Form1 // @@ -337,6 +409,11 @@ private void InitializeComponent() AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1230, 629); + Controls.Add(btnGruss); + Controls.Add(btnHello); + Controls.Add(btnAnrede); + Controls.Add(btnSGDH); + Controls.Add(btnMFG); Controls.Add(lblActiveChar); Controls.Add(label1); Controls.Add(lblEntryMode); @@ -389,6 +466,11 @@ private void InitializeComponent() private Label lblEntryMode; private Label label1; private Label lblActiveChar; + private Button btnMFG; + private Button btnSGDH; + private Button btnAnrede; + private Button btnHello; + private Button btnGruss; } } diff --git a/T9KeyboardApp/Form1.cs b/T9KeyboardApp/Form1.cs index f0ac4b6..0953ba8 100644 --- a/T9KeyboardApp/Form1.cs +++ b/T9KeyboardApp/Form1.cs @@ -5,6 +5,7 @@ namespace T9KeyboardApp public partial class Form1 : Form { public Mode EntryMode { get; set; } + public List AddTextButtons { get; set; } int counter = 0; bool timerIsRunning = false; Button? buttonPressed = null; @@ -12,6 +13,17 @@ public partial class Form1 : Form public Form1() { InitializeComponent(); + AddTextButtons = new List() + { + new(textBox1, "lich"), new(textBox1, "keit"), new(textBox1, "schaft"), + }; + foreach (AddTextButton button in AddTextButtons) + { + Controls.Add(button); + button.Show(); + } + + textBox1.Height = 480; EntryMode = Mode.Normal; DisplayEntryMode(); } @@ -103,9 +115,12 @@ private void ButtonClick(object sender, EventArgs e) if (int.TryParse("" + buttonPressed?.Text[0], out int index)) { Buttons.buttons[index].Hit(); - lblActiveChar.Text = "" + Buttons.buttons[index].Value(); + lblActiveChar.Text = "" + Buttons.buttons[index].Value().ToString(); + } + else + { + OperatorButton(buttonPressed?.Text[0]); } - else OperatorButton(buttonPressed?.Text[0]); textBox1.Select(); } @@ -114,24 +129,18 @@ private void OperatorButton(char? name) { if (name == null) return; - switch (name) - { - case ',': - Buttons.buttons[10].Hit(); - break; - case '-': - Buttons.buttons[11].Hit(); - break; - case '/': - Buttons.buttons[12].Hit(); - break; - case '*': - Buttons.buttons[13].Hit(); - break; - case '+': - Buttons.buttons[14].Hit(); - break; - } + ButtonKey? representingButton + = name switch + { + ',' => Buttons.buttons[10], + '-' => Buttons.buttons[11], + '/' => Buttons.buttons[12], + '*' => Buttons.buttons[13], + '+' => Buttons.buttons[14], + _ => null + }; + representingButton?.Hit(); + lblActiveChar.Text = "" + representingButton?.Value(); } private char? OperatorWrite(char? name) @@ -139,21 +148,15 @@ private void OperatorButton(char? name) char? value = null; if (name == null) return value; - switch (name) - { - case ',': - return Buttons.buttons[10].Key(EntryMode); - case '-': - return Buttons.buttons[11].Key(EntryMode); - case '/': - return Buttons.buttons[12].Key(EntryMode); - case '*': - return Buttons.buttons[13].Key(EntryMode); - case '+': - return Buttons.buttons[14].Key(EntryMode); - default: - return value; - } + return name switch + { + ',' => Buttons.buttons[10].Key(EntryMode), + '-' => Buttons.buttons[11].Key(EntryMode), + '/' => Buttons.buttons[12].Key(EntryMode), + '*' => Buttons.buttons[13].Key(EntryMode), + '+' => Buttons.buttons[14].Key(EntryMode), + _ => value, + }; } private void TimerKeysWait_Tick(object sender, EventArgs e) @@ -197,5 +200,41 @@ private void SwitchMode() } private void DisplayEntryMode() => lblEntryMode.Text = Params.EntryModes[(int)EntryMode]; + + private void Button_MFG_Click(object sender, EventArgs e) + { + textBox1.Text += Environment.NewLine + Environment.NewLine + + "Mit freundlichen Grüßen" + Environment.NewLine + + Environment.NewLine; + textBox1.Select(); + } + + private void BtnSGDH_Click(object sender, EventArgs e) + { + textBox1.Text += "Sehr geehrte Damen und Herren," + Environment.NewLine + + Environment.NewLine; + textBox1.Select(); + } + + private void BtnAnrede_Click(object sender, EventArgs e) + { + textBox1.Text += "Liebe"; + textBox1.Select(); + } + + private void BtnHello_Click(object sender, EventArgs e) + { + textBox1.Text += "Hallo "; + textBox1.Select(); + } + + private void BtnGruss_Click(object sender, EventArgs e) + { + textBox1.Text += Environment.NewLine + Environment.NewLine + + "Herzliche Grüße" + Environment.NewLine + + Environment.NewLine; + textBox1.Select(); + } + } } diff --git a/T9KeyboardApp/Form1.resx b/T9KeyboardApp/Form1.resx index 774dcc2..73aa81b 100644 --- a/T9KeyboardApp/Form1.resx +++ b/T9KeyboardApp/Form1.resx @@ -120,4 +120,7 @@ 17, 17 + + 25 + \ No newline at end of file