MainForm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WinLists
  11. {
  12. public partial class MainForm : Form
  13. {
  14. public MainForm()
  15. {
  16. InitializeComponent();
  17. }
  18. private void MainFormLoad(object sender, EventArgs e)
  19. {
  20. lblOutput.Visible = false;
  21. }
  22. /// <summary>
  23. /// Вычисление решения по нажатию на кнопку
  24. /// </summary>
  25. private void btnLaunchClick(object sender, EventArgs e)
  26. {
  27. // Разбить строку на слова
  28. if (lbItems.SelectedIndex == -1) {
  29. MessageBox.Show("Выберите элемент из списка!");
  30. return;
  31. }
  32. var words = Convert.ToString(lbItems.Items[lbItems.SelectedIndex]).Split(' ');
  33. // Пройтись по каждому слову, сформировать строку ответа
  34. string output = "";
  35. foreach (var word in words)
  36. {
  37. output += word.Substring(1, word.Length - 1); // Убираем первую букву слова
  38. output += " ";
  39. }
  40. // Обновляем надпись
  41. lblOutput.Visible = true;
  42. lblOutput.Text = output;
  43. }
  44. }
  45. }