Advertisement
Guest User

Untitled

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