Hyluss

Przykladowe zadanie na kurs - GP

Jan 13th, 2020
326
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApp1
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         private Stopwatch timer;
  17.  
  18.         private string[] tablicaZdan = new[]
  19.             {"Jestę programistą", "Giganci programowania!", "Uszanowanko programowanko", "Mój pierwszy program"};
  20.  
  21.         private string wybraneZdanie = "";
  22.  
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.  
  29.         private void textBox1_TextChanged(object sender, EventArgs e)
  30.         {
  31.             // Sprawdź czy wybrane zdanie zawiera zawartość wpisana w obszar pola tekstowego
  32.             if (wybraneZdanie.Contains(textBoxObszarWpisywania.Text))
  33.             {
  34.                 // jesli tak zmien kolor czcionki na zielony
  35.                 textBoxObszarWpisywania.ForeColor = Color.Green;
  36.             }
  37.             else
  38.             {
  39.                 textBoxObszarWpisywania.ForeColor = Color.Red;
  40.             }
  41.  
  42.             // sprawdz czy wybrane zdanie jest takie same jak te wpisane w obszarze pola tekstowego
  43.             if (wybraneZdanie == textBoxObszarWpisywania.Text && textBoxObszarWpisywania.Text != "")
  44.             {
  45.                 // zatrzymaj stoper
  46.                 timer.Stop();
  47.                 // wypisz do labela swój wynik
  48.                 labelWynik.Text = "Wypisałes tekst '" + wybraneZdanie + "' w czasie " + timer.Elapsed.Seconds + " sekund. Super!";
  49.             }
  50.         }
  51.  
  52.         private void textBox1_MouseClick(object sender, MouseEventArgs e)
  53.         {
  54.             // Wymaż tekst po kliknieciu w textbox
  55.             textBoxObszarWpisywania.Text = "";
  56.  
  57.             // Uruchom stoper
  58.             timer = new Stopwatch();
  59.             timer.Start();
  60.         }
  61.  
  62.         private void button2_Click(object sender, EventArgs e)
  63.         {
  64.             // Wymaż tekst po wylosowaniu nowego zdania
  65.             textBoxObszarWpisywania.Text = "";
  66.  
  67.             // Wylosuj tekst z tablicy
  68.             Random random = new Random();
  69.             wybraneZdanie = tablicaZdan[random.Next(0, tablicaZdan.Length)];
  70.  
  71.             // Wyswietl wylosowany tekst w labelu
  72.             labelWylosowanyTekst.Text = "Wpisz tekst: " + wybraneZdanie;
  73.  
  74.         }
  75.  
  76.     }
  77. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment