Skip to content

Commit

Permalink
add automatically positioned buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
DGrothe-PhD committed Oct 7, 2023
1 parent 6b7211e commit e397928
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 36 deletions.
47 changes: 47 additions & 0 deletions T9KeyboardApp/AddTextButton.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
84 changes: 83 additions & 1 deletion T9KeyboardApp/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 74 additions & 35 deletions T9KeyboardApp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ namespace T9KeyboardApp
public partial class Form1 : Form
{
public Mode EntryMode { get; set; }
public List<AddTextButton> AddTextButtons { get; set; }
int counter = 0;
bool timerIsRunning = false;
Button? buttonPressed = null;

public Form1()
{
InitializeComponent();
AddTextButtons = new List<AddTextButton>()
{
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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -114,46 +129,34 @@ 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)
{
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)
Expand Down Expand Up @@ -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();
}

}
}
3 changes: 3 additions & 0 deletions T9KeyboardApp/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<metadata name="timerKeysWait.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>

0 comments on commit e397928

Please sign in to comment.