Anonim_999

2

May 9th, 2022
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5.  
  6. namespace WindowsFormsApplication1
  7. {
  8.     public partial class Form2 : Form
  9.     {
  10.         public Form2()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void button1_Click(object sender, EventArgs e)
  16.         {
  17.             if (SecondName.Text != "" && FirstName.Text != "" && LastName.Text != "")
  18.             {
  19.                 ResetAlerts();
  20.  
  21.                 if (SecondName.Text.Length > 35)
  22.                     ShowAlert(SecondNameAlert, Color.Red);
  23.                 else if (FirstName.Text.Length > 35)
  24.                     ShowAlert(FirstNameAlert, Color.Red);
  25.                 else if (LastName.Text.Length > 35)
  26.                     ShowAlert(LastNameAlert, Color.Red);
  27.                 else
  28.                 {
  29.                     Form3 ContactAdressUserForm = new Form3();
  30.                     ContactAdressUserForm.Show();
  31.                     Hide();
  32.                 }
  33.             }else
  34.             {
  35.                 ShowAlert(Alert, Color.Red);
  36.             }
  37.         }
  38.  
  39.         private void ShowAlert(Label label, Color color)
  40.         {
  41.             label.BackColor = color;
  42.             label.Show();
  43.         }
  44.  
  45.         private void ResetAlerts()
  46.         {
  47.             List<Label> labels = new List<Label> { FirstNameAlert, SecondNameAlert, LastNameAlert, Alert };
  48.  
  49.             foreach (var alert in labels)
  50.             {
  51.                 alert.BackColor = Color.White;
  52.                 alert.Hide();
  53.             }
  54.         }
  55.  
  56.         private void SecondName_KeyPress(object sender, KeyPressEventArgs e)
  57.         {
  58.             AbortNumbers(e);
  59.         }
  60.  
  61.         private void FirstName_KeyPress(object sender, KeyPressEventArgs e)
  62.         {
  63.             AbortNumbers(e);
  64.         }
  65.  
  66.         private void LastName_KeyPress(object sender, KeyPressEventArgs e)
  67.         {
  68.             AbortNumbers(e);
  69.         }
  70.  
  71.         private void AbortNumbers(KeyPressEventArgs e)
  72.         {
  73.             char input = e.KeyChar;
  74.  
  75.             if (Char.IsDigit(input))
  76.                 e.Handled = true;
  77.         }
  78.  
  79.         private void label1_Click(object sender, EventArgs e)
  80.         {
  81.  
  82.         }
  83.  
  84.         private void label2_Click(object sender, EventArgs e)
  85.         {
  86.  
  87.         }
  88.  
  89.         private void label4_Click(object sender, EventArgs e)
  90.         {
  91.  
  92.         }
  93.  
  94.         private void label3_Click(object sender, EventArgs e)
  95.         {
  96.  
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment