Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- private Stopwatch timer;
- private string[] tablicaZdan = new[]
- {"Jestę programistą", "Giganci programowania!", "Uszanowanko programowanko", "Mój pierwszy program"};
- private string wybraneZdanie = "";
- public Form1()
- {
- InitializeComponent();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- // Sprawdź czy wybrane zdanie zawiera zawartość wpisana w obszar pola tekstowego
- if (wybraneZdanie.Contains(textBoxObszarWpisywania.Text))
- {
- // jesli tak zmien kolor czcionki na zielony
- textBoxObszarWpisywania.ForeColor = Color.Green;
- }
- else
- {
- textBoxObszarWpisywania.ForeColor = Color.Red;
- }
- // sprawdz czy wybrane zdanie jest takie same jak te wpisane w obszarze pola tekstowego
- if (wybraneZdanie == textBoxObszarWpisywania.Text && textBoxObszarWpisywania.Text != "")
- {
- // zatrzymaj stoper
- timer.Stop();
- // wypisz do labela swój wynik
- labelWynik.Text = "Wypisałes tekst '" + wybraneZdanie + "' w czasie " + timer.Elapsed.Seconds + " sekund. Super!";
- }
- }
- private void textBox1_MouseClick(object sender, MouseEventArgs e)
- {
- // Wymaż tekst po kliknieciu w textbox
- textBoxObszarWpisywania.Text = "";
- // Uruchom stoper
- timer = new Stopwatch();
- timer.Start();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- // Wymaż tekst po wylosowaniu nowego zdania
- textBoxObszarWpisywania.Text = "";
- // Wylosuj tekst z tablicy
- Random random = new Random();
- wybraneZdanie = tablicaZdan[random.Next(0, tablicaZdan.Length)];
- // Wyswietl wylosowany tekst w labelu
- labelWylosowanyTekst.Text = "Wpisz tekst: " + wybraneZdanie;
- }
- }
- }
Advertisement