ErrorProvider

Скрыть

Показать

Копировать
  Form1.cs  
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace _0079 {
 public partial class Form1 : Form {
  public Form1() {
   InitializeComponent();
  }
  // поле ввода username
  private void textBoxUserName_Validated(object sender, EventArgs e) {
   if(string.IsNullOrEmpty(textBoxUserName.Text)) {
    errorProviderUserName.Icon = Properties.Resources.error;
    errorProviderUserName.SetError(textBoxUserName, "Error");
   }
   else {
    errorProviderUserName.Icon = Properties.Resources.ok;
    errorProviderUserName.SetError(textBoxUserName, "OK");
   }
  }
 
  private void textBoxPassword_Validated(object sender, EventArgs e) {
   if(string.IsNullOrEmpty(textBoxPassword.Text)) {
    errorProviderPassword.Icon = Properties.Resources.error;
    errorProviderPassword.SetError(textBoxPassword, "Error");
   }
   else {
    errorProviderPassword.Icon = Properties.Resources.ok;
    errorProviderPassword.SetError(textBoxPassword, "OK");
   }
  }
 
  private void buttonOK_Click(object sender, EventArgs e) {
   if(string.IsNullOrEmpty(textBoxUserName.Text)) {
    errorProviderUserName.Icon = Properties.Resources.error;
    errorProviderUserName.SetError(textBoxUserName, "Error");
   }
   else {
    errorProviderUserName.Icon = Properties.Resources.ok;
    errorProviderUserName.SetError(textBoxUserName, "OK");
   }
   if(string.IsNullOrEmpty(textBoxPassword.Text)) {
    errorProviderPassword.Icon = Properties.Resources.error;
    errorProviderPassword.SetError(textBoxPassword, "Error");
   }
   else {
    errorProviderPassword.Icon = Properties.Resources.ok;
    errorProviderPassword.SetError(textBoxPassword, "OK");
   }
   if(textBoxUserName.Text == "sergey" & textBoxPassword.Text == "123456") {
    MessageBox.Show("Welcome!");
   }
   else {
    MessageBox.Show("Excuse me, try again.");
   }
  }
 }
}