Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  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.  
  11. namespace WindowsFormsApp1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.             listBox1.SelectionMode = SelectionMode.MultiSimple;
  19.         }
  20.  
  21.         private void Button1_Click(object sender, EventArgs e)
  22.         {
  23.             if (textBox1.Text != "")
  24.             {
  25.                 listBox1.Items.Add(textBox1.Text);
  26.                 textBox1.Clear();
  27.             }
  28.             else
  29.             {
  30.                 MessageBox.Show("TextBox пуст", "Ошибка");
  31.             }
  32.         }
  33.  
  34.         private void Button2_Click(object sender, EventArgs e)
  35.         {
  36.             if (listBox1.SelectedItems.Count > 0)
  37.             {
  38.  
  39.                 string s = "";
  40.                 foreach (var item in listBox1.SelectedItems)
  41.                 {
  42.  
  43.                     if (Int32.TryParse(item.ToString(), out int num))
  44.                     {
  45.                         if (num % 7 == 0 && num < 0)
  46.                         {
  47.                             s += $"{num}\n";
  48.                         }
  49.                     }
  50.  
  51.                 }
  52.                 if (string.IsNullOrEmpty(s)) MessageBox.Show("Нет четных выделенных элементов", "Сообщение");
  53.                 else MessageBox.Show(s);
  54.  
  55.  
  56.             }
  57.             else
  58.             {
  59.                 MessageBox.Show("Нет выделенных элементов", "Ошибка");
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement