In this article I will show you how you can limit or
restrict number of characters in textbox c#.net in windows application.
Some of my previous articles are as follows: AutoSuggest
DropDownList In Windows Application Using C#.Net, Random
Character and String Generation Using C#.Net, Windows Application and Linq,
Strong
Random String Password Generation Using C#.Net, Login
Form By UserType OR User Role In Windows Application In C#.Net , Linq, Display
Message With Warning icon in Windows Application Using C#.Net, Stylish
ToolStrip Button Control With Image and Text Control In Windows Application
Using C#.Net.
So for this article first we will create a new windows
application create the below form.
Now add the below code into the form.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void textBox1_TextChanged(object sender, EventArgs
e)
{
if
(textBox1.Text.Length <= 10)
{
label1.Text = "Total No of Characters : " +
textBox1.Text.Length;
}
}
private
void Form1_Load(object
sender, EventArgs e)
{
textBox1.MaxLength = 10;
}
}
}
|
On page load I have assign the max length of the textbox. And
on textbox change I have calculated the total no of character added in the
textbox.
Now we have run the application and check the output.
DOWNLOAD
0 comments:
Please let me know your view