.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to count number of characters enterd in a textbox currently?

Posted By:Syed Shakeer Hussain       Posted Date: August 15, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  
 

I had used two textboxs.one for entering text and another textbox is used to display number of characters
enterd.
Select you textbox choose events.In events double click on 'TextChanged' Event and write the below code.

 if (txtmessage.Text.Length > 0)
            {
             
                txtcount.Text = txtmessage.Text.Length.ToString();
            }
            else
                txtcount.Text = Convert.ToString(0);
           

The Desing of Windows form

In form1.cs the complete code is written as follows

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace counttextusingevent
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void txtmessage_TextChanged(object sender, EventArgs e)
        {
            if (txtmessage.Text.Length > 0)
            {
             
                txtcount.Text = txtmessage.Text.Length.ToString();
            }
            else
                txtcount.Text = Convert.ToString(0);
           
        }
    }
}

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend