diff --git a/Glosor.slnx b/Glosor.slnx new file mode 100644 index 0000000..b95b38f --- /dev/null +++ b/Glosor.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Glosor/Form1.Designer.cs b/Glosor/Form1.Designer.cs new file mode 100644 index 0000000..848176a --- /dev/null +++ b/Glosor/Form1.Designer.cs @@ -0,0 +1,188 @@ +namespace Glosor +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + lst_words = new ListBox(); + btn_add = new Button(); + tbx_original = new TextBox(); + tbx_translation = new TextBox(); + btn_start = new Button(); + btn_clear = new Button(); + lbl_original = new Label(); + tbx_input = new TextBox(); + btn_skip = new Button(); + btn_check = new Button(); + lbl_correct = new Label(); + SuspendLayout(); + // + // lst_words + // + lst_words.FormattingEnabled = true; + lst_words.ItemHeight = 25; + lst_words.Location = new Point(247, 40); + lst_words.Name = "lst_words"; + lst_words.Size = new Size(314, 129); + lst_words.TabIndex = 0; + lst_words.Visible = false; + // + // btn_add + // + btn_add.Location = new Point(449, 175); + btn_add.Name = "btn_add"; + btn_add.Size = new Size(112, 34); + btn_add.TabIndex = 1; + btn_add.Text = "Lägg till"; + btn_add.UseVisualStyleBackColor = true; + btn_add.Visible = false; + btn_add.Click += btn_add_Click; + // + // tbx_original + // + tbx_original.Location = new Point(247, 175); + tbx_original.Name = "tbx_original"; + tbx_original.PlaceholderText = "Glosa"; + tbx_original.Size = new Size(196, 31); + tbx_original.TabIndex = 2; + tbx_original.Visible = false; + // + // tbx_translation + // + tbx_translation.Location = new Point(247, 212); + tbx_translation.Name = "tbx_translation"; + tbx_translation.PlaceholderText = "Översättning"; + tbx_translation.Size = new Size(196, 31); + tbx_translation.TabIndex = 3; + tbx_translation.Visible = false; + // + // btn_start + // + btn_start.Location = new Point(449, 215); + btn_start.Name = "btn_start"; + btn_start.Size = new Size(112, 34); + btn_start.TabIndex = 4; + btn_start.Text = "Starta Prov"; + btn_start.UseVisualStyleBackColor = true; + btn_start.Visible = false; + btn_start.Click += btn_start_Click; + // + // btn_clear + // + btn_clear.Location = new Point(567, 40); + btn_clear.Name = "btn_clear"; + btn_clear.Size = new Size(112, 34); + btn_clear.TabIndex = 5; + btn_clear.Text = "Rensa"; + btn_clear.UseVisualStyleBackColor = true; + btn_clear.Visible = false; + btn_clear.Click += btn_clear_Click; + // + // lbl_original + // + lbl_original.AutoSize = true; + lbl_original.Location = new Point(345, 99); + lbl_original.Name = "lbl_original"; + lbl_original.Size = new Size(59, 25); + lbl_original.TabIndex = 6; + lbl_original.Text = "label1"; + lbl_original.TextAlign = ContentAlignment.MiddleLeft; + // + // tbx_input + // + tbx_input.Location = new Point(345, 127); + tbx_input.Name = "tbx_input"; + tbx_input.Size = new Size(150, 31); + tbx_input.TabIndex = 7; + tbx_input.TextAlign = HorizontalAlignment.Center; + // + // btn_skip + // + btn_skip.Location = new Point(425, 164); + btn_skip.Name = "btn_skip"; + btn_skip.Size = new Size(112, 34); + btn_skip.TabIndex = 8; + btn_skip.Text = "Skippa"; + btn_skip.UseVisualStyleBackColor = true; + btn_skip.Click += btn_skip_Click; + // + // btn_check + // + btn_check.Location = new Point(307, 164); + btn_check.Name = "btn_check"; + btn_check.Size = new Size(112, 34); + btn_check.TabIndex = 9; + btn_check.Text = "Svara"; + btn_check.UseVisualStyleBackColor = true; + btn_check.Click += btn_check_Click; + // + // lbl_correct + // + lbl_correct.AutoSize = true; + lbl_correct.Location = new Point(384, 201); + lbl_correct.Name = "lbl_correct"; + lbl_correct.Size = new Size(0, 25); + lbl_correct.TabIndex = 10; + lbl_correct.TextAlign = ContentAlignment.MiddleCenter; + // + // Form1 + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(lbl_correct); + Controls.Add(btn_check); + Controls.Add(btn_skip); + Controls.Add(tbx_input); + Controls.Add(lbl_original); + Controls.Add(btn_clear); + Controls.Add(btn_start); + Controls.Add(tbx_translation); + Controls.Add(tbx_original); + Controls.Add(btn_add); + Controls.Add(lst_words); + Name = "Form1"; + Text = "Glosor"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ListBox lst_words; + private Button btn_add; + private TextBox tbx_original; + private TextBox tbx_translation; + private Button btn_start; + private Button btn_clear; + private Label lbl_original; + private TextBox tbx_input; + private Button btn_skip; + private Button btn_check; + private Label lbl_correct; + } +} diff --git a/Glosor/Form1.cs b/Glosor/Form1.cs new file mode 100644 index 0000000..90cc619 --- /dev/null +++ b/Glosor/Form1.cs @@ -0,0 +1,134 @@ +namespace Glosor +{ + public partial class Form1 : Form + { + public Dictionary Words = new Dictionary(); // original, translation + int step = 0; + int points = 0; + string correctAnswer; + + bool useExampleWords = true; + + public Form1() + { + InitializeComponent(); + SetEditingMode(true); + AddExampleWords(); + } + + public void AddExampleWords() + { + if (!useExampleWords) return; + + AddWord("Apple", "Äpple"); + AddWord("Banana", "Banan"); + AddWord("Orange", "Apelsin"); + AddWord("Watermelon", "Vattenmelon"); + } + + // Actions + + public void AddWord(string original, string translation) + { + Words.Add(original, translation); + lst_words.Items.Add(original + " -> " + translation); + } + + private void SetEditingMode(bool editing) + { + tbx_translation.Visible = editing; + tbx_original.Visible = editing; + lst_words.Visible = editing; + btn_clear.Visible = editing; + btn_add.Visible = editing; + btn_start.Visible = editing; + + lbl_correct.Visible = !editing; + tbx_input.Visible = !editing; + lbl_original.Visible = !editing; + btn_check.Visible = !editing; + btn_skip.Visible = !editing; + } + + public void StartTest() + { + SetEditingMode(false); + + step = 0; + points = 0; + + Question(); + } + + // Questioning logic + + public void Question() + { + if (step == Words.Count) + { + MessageBox.Show("Du fick " + points.ToString() + " av " + Words.Count + " poäng"); + SetEditingMode(true); + return; + } + + var entry = Words.ElementAt(step); + string original = entry.Key; + correctAnswer = entry.Value.ToLower(); + + lbl_original.Text = original; + tbx_input.Text = ""; + lbl_correct.Text = ""; + + tbx_input.Focus(); + + step++; + } + + public void Answer() + { + string input = tbx_input.Text.ToLower(); + + if (input == correctAnswer) + { + points++; + Question(); + } + else + { + lbl_correct.Text = "Fel Svar"; + } + } + + // Buttons + + private void btn_add_Click(object sender, EventArgs e) + { + string original = tbx_original.Text; + string translation = tbx_translation.Text; + tbx_original.Text = ""; + tbx_translation.Text = ""; + AddWord(original, translation); + } + + private void btn_clear_Click(object sender, EventArgs e) + { + lst_words.Items.Clear(); + Words.Clear(); + } + + private void btn_start_Click(object sender, EventArgs e) + { + StartTest(); + } + + private void btn_check_Click(object sender, EventArgs e) + { + Answer(); + } + + private void btn_skip_Click(object sender, EventArgs e) + { + Question(); + } + } +} diff --git a/Glosor/Form1.resx b/Glosor/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Glosor/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Glosor/Glosor.csproj b/Glosor/Glosor.csproj new file mode 100644 index 0000000..663fdb8 --- /dev/null +++ b/Glosor/Glosor.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/Glosor/Program.cs b/Glosor/Program.cs new file mode 100644 index 0000000..60cdd3b --- /dev/null +++ b/Glosor/Program.cs @@ -0,0 +1,17 @@ +namespace Glosor +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file