MainForm.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /// <summary>
  19. /// Метод загрузки главной формы
  20. /// </summary>
  21. /// <param name="sender"></param>
  22. /// <param name="e"></param>
  23. private void MainFormLoad(object sender, EventArgs e)
  24. {
  25. lblOutput.Visible = false;
  26. }
  27. /// <summary>
  28. /// Вычисление решения по нажатию на кнопку
  29. /// </summary>
  30. private void btnLaunchClick(object sender, EventArgs e)
  31. {
  32. // Разбить строку на слова
  33. if (lbItems.SelectedIndex == -1) {
  34. MessageBox.Show("Выберите элемент из списка!");
  35. return;
  36. }
  37. var words = Convert.ToString(lbItems.Items[lbItems.SelectedIndex]).Split(' ');
  38. // Пройтись по каждому слову, сформировать строку ответа
  39. string output = "";
  40. foreach (var word in words)
  41. {
  42. output += word.Substring(1, word.Length - 1); // Убираем первую букву слова
  43. output += " ";
  44. }
  45. // Обновляем надпись
  46. lblOutput.Visible = true;
  47. lblOutput.Text = output;
  48. }
  49. }
  50. }