private void End() { Graphics Graph; Graphics Graph2; Graph = splitContainer1.Panel1.CreateGraphics(); Graph2 = splitContainer1.Panel2.CreateGraphics(); Graph.Clear(BackColor); Graph2.Clear(BackColor); timer2.Enabled = false; IfStarted = false; button3.Enabled = true; button1.Enabled = true; button2.Enabled = true; button4.Enabled = false; button5.Enabled = false; menuStrip1.Enabled = true; label3.Text = $"{Properties.Settings.Default.Timer / 60}:{Properties.Settings.Default.Timer % 60}"; Typed = null; MissclickPercentage = Missclicks / CharCounter * 100; MissclickPercentage = Math.Round(MissclickPercentage, 1); try { Speed = 60 / (Properties.Settings.Default.Timer - TimeLeft) * CharCounter; TimeLeft = Properties.Settings.Default.Timer; } catch (DivideByZeroException) { Speed = 0; } label16.Text = Speed.ToString(); label17.Text = MissclickPercentage.ToString(); label19.Text = CharCounter.ToString(); label13.Text = Missclicks.ToString(); }
private void MainForm_KeyPress(object sender, KeyPressEventArgs e) { if (IfStarted == false) { return; } try { char FirstChar = Result.First <char>(); button3.Enabled = false; button1.Enabled = false; button2.Enabled = false; button4.Enabled = true; button5.Enabled = true; menuStrip1.Enabled = false; button5.Visible = true; button6.Visible = false; label9.Text = e.KeyChar.ToString(); Graphics Graph; Graphics Graph2; Font font = new Font("Sans Serif", Properties.Settings.Default.TextSize); Graph = splitContainer1.Panel1.CreateGraphics(); Graph2 = splitContainer1.Panel2.CreateGraphics(); Graph.Clear(BackColor); Graph2.Clear(BackColor); timer2.Enabled = true; if (e.KeyChar == FirstChar) { Typed += e.KeyChar; if (TextRenderer.MeasureText(Typed, font).Width > 620) { Typed = Typed.Remove(0, 1); } Result = Result.Remove(0, 1); Graph.Clear(BackColor); Graph2.Clear(BackColor); Graph.DrawString(Result, font, Brushes.Black, 1, 30); Graph2.DrawString(Typed, font, Brushes.Black, 1, 30); } else { ++Missclicks; Graph.DrawString(Result, font, Brushes.Black, 1, 30); Graph2.DrawString(Typed, font, Brushes.Black, 1, 30); } ++CharCounter; } catch (InvalidOperationException) { End(); SessionStats(); } }