In this article I will show you how you can handle error in windows
application using c#.net. This will help your user to enter correct data.
Some of my previous articles are as follows: Restrict
User to Enter Only Negative, Non-Negative and Decimal Number in TextBox Using
C#.Net in Windows Application, Dynamically
Add textbox control on button click in windows application using C#.net and
VB.net, Paging
in DataGridview Using C#.Net In Windows Application, Show
Progressbar While Moving Folder File From One Directory To Other Using C#.Net
In Windows Application, Windows
Application - Excel Sheet Name in C#.Net, WaterMark
TextBox In Windows Applications Using C# and VB.Net.
So for this article first we will create a new windows
application and in this form we will add
a button and a text box and a button control.
Now go to code end and add the below code to validate the
textbox value.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
//Error
handeling in windows app;lkication using c#.net
private
void button1_Click(object
sender, EventArgs e)
{
string
dataMesage = Validationmessage();
if
(dataMesage == "")
{
MessageBox.Show("Your name is : " + txtname.Text);
}
else
{
MessageBox.Show(dataMesage,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public
string Validationmessage()
{
string
dataMesssage = "";
if
(txtname.Text == "")
{
dataMesssage = "Please enter name.";
}
return
dataMesssage;
}
}
}
|
So here is the output.
DOWNLOAD
0 comments:
Please let me know your view