Counting enterd text using C#

Description :


Drag and drop two textboxs on windows form.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);


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);
}
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: