Anonim_999

3

May 9th, 2022
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 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.Windows.Forms;
  7.  
  8. namespace WindowsFormsApplication1
  9. {
  10.     public partial class Form3 : Form
  11.     {
  12.         public Form3()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private void button1_Click(object sender, EventArgs e)
  18.         {
  19.             if (PhoneNumber.Text != "" && EmailAdress.Text != "")
  20.             {
  21.                 ResetAlert();
  22.  
  23.                 if (PhoneNumber.Text.Length > 11)
  24.                     ShowAlert(PhoneNumberAlert,Color.Red);
  25.                 else if (EmailAdress.Text.Length > 40)
  26.                     ShowAlert(EmailAdressAlert,Color.Red);
  27.                 else
  28.                 {
  29.                     Form5 choseRoute = new Form5();
  30.                     choseRoute.Show();
  31.                     Hide();
  32.                 }
  33.             }
  34.         }
  35.  
  36.         private void ShowAlert(Label label, Color color)
  37.         {
  38.             label.BackColor = color;
  39.             label.Show();
  40.         }
  41.  
  42.         private void ResetAlert()
  43.         {
  44.             List<Label> alerts = new List<Label> { PhoneNumberAlert, EmailAdressAlert, Alert};
  45.  
  46.             foreach (var alert in alerts)
  47.             {
  48.                 alert.BackColor = Color.White;
  49.                 alert.Hide();
  50.             }
  51.         }
  52.  
  53.         private void textBox1_TextChanged(object sender, EventArgs e)
  54.         {
  55.  
  56.         }
  57.  
  58.         private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  59.         {
  60.             char number = e.KeyChar;
  61.  
  62.             if (!Char.IsDigit(number) && number != 8)
  63.                 e.Handled = true;
  64.         }
  65.  
  66.         private void Form3_Load(object sender, EventArgs e)
  67.         {
  68.  
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment