Error Provider Window Application in C# .Net

Step 1: Open Visual Studio (any version) installed in your machine. I have VS2012,

Open

Click New Project. This opens a new window which looks like the image below.

New project

Step 2: Enter your application name and click OK.

application Name

Step 3: Design your Windows application - Drag and drop one textbox, one button, one label and errorProvider. Click the button and add the source code.

Design

  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. using System.Diagnostics;  
  11. using System.ComponentModel;  
  12. using System.Text;  
  13.   
  14. namespace Error2  
  15. {  
  16.     public partial class Form1 : Form  
  17.     {  
  18.   
  19.         public Form1()  
  20.         {  
  21.             InitializeComponent();  
  22.         }  
  23.   
  24.         private void button1_Click(object sender, EventArgs e)  
  25.         {  
  26.             if (textBox1.Text == "krishna")  
  27.             {  
  28.                 errorProvider1.Clear();  
  29.                 MessageBox.Show("This is Valid Data");  
  30.                   
  31.             }  
  32.             else  
  33.             {  
  34.                 errorProvider1.SetError(textBox1,"please enter correct data");  
  35.                 MessageBox.Show("please enter correct data");  
  36.                 errorProvider1.BlinkStyle = ErrorBlinkStyle.BlinkIfDifferentError;  
  37.   
  38.             }  
  39.         }  
  40.     }  
  41. }  
Output will be the following screenshots

Outputs

Outputs

 

Ebook Download
View all
Learn
View all