Anonim_999

MainZad1

Jun 16th, 2022
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.53 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 zad1
  12. {
  13.     public partial class Zad1 : Form
  14.     {
  15.         private string _text;
  16.  
  17.         public Zad1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
  23.         {
  24.  
  25.         }
  26.  
  27.         private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
  28.         {
  29.             var list = sender as CheckedListBox;
  30.  
  31.             if (e.NewValue == CheckState.Checked)
  32.                 foreach (int index in list.CheckedIndices)
  33.                     if (index != e.Index)
  34.                         list.SetItemChecked(index, false);
  35.         }
  36.  
  37.         private void button1_Click(object sender, EventArgs e)
  38.         {
  39.             richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
  40.             richTextBox1.Text = "";
  41.             _text = "";
  42.  
  43.             if (NameTextBox.Text != "")
  44.             {
  45.                 _text += $"Здравствуйте, {NameTextBox.Text}!\n";
  46.  
  47.                 if (checkedListBox1.GetItemChecked(0))
  48.                     _text += $"Наша компания рада\nприветствовать мужчину,\nУвлеченного ";
  49.                 else if (checkedListBox1.GetItemChecked(1))
  50.                     _text += $"Наша компания рада\nприветствовать женщину,\nУвлеченной ";
  51.                 else
  52.                     _text += $"Наша компания рада\nприветствовать вас,\nМы ценим, что вы увлеченны ";
  53.  
  54.                 if (checkedListBox2.CheckedItems.Count > 0)
  55.                 {
  56.                     if (checkedListBox2.SelectedIndex == 0)
  57.                         _text += $"музыкой";
  58.  
  59.                     if (checkedListBox2.SelectedIndex == 1)
  60.                         _text += $"спортом";
  61.  
  62.                     if (checkedListBox2.SelectedIndex == 2)
  63.                         _text += $"наукой";
  64.  
  65.                     if (checkedListBox2.SelectedIndex == 3)
  66.                         _text += $"живописью";
  67.                 }
  68.                 else
  69.                     _text += $" скрывать свои увлечения";
  70.  
  71.                 richTextBox1.Text = _text;
  72.             }
  73.             else
  74.             {
  75.                 MessageBox.Show("Пожалуйста, введите Ваше имя");
  76.             }
  77.         }
  78.  
  79.         private void Form1_Load(object sender, EventArgs e)
  80.         {
  81.             checkedListBox1.SetItemChecked(0, true);
  82.         }
  83.  
  84.         private void checkedListBox2_ItemCheck(object sender, ItemCheckEventArgs e)
  85.         {
  86.             var list = sender as CheckedListBox;
  87.             if (e.NewValue == CheckState.Checked)
  88.                 foreach (int index in list.CheckedIndices)
  89.                     if (index != e.Index)
  90.                         list.SetItemChecked(index, false);
  91.         }
  92.  
  93.         private void button2_Click(object sender, EventArgs e)
  94.         {
  95.             checkedListBox1.SetItemChecked(0, true);
  96.             NameTextBox.Text = "";
  97.             richTextBox1.Text = "";
  98.  
  99.             for (int i = 0; i < checkedListBox2.Items.Count; i++)
  100.                 if (checkedListBox2.GetItemChecked(i))
  101.                     checkedListBox2.SetItemChecked(i, false);
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment