有些人可以帮我提一下标签字数请用C# [英] Can some please help me with a label word count please in C#

查看:45
本文介绍了有些人可以帮我提一下标签字数请用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试让我的Windows窗体项目上的标签计算在richTextbox中输入的字符数。我的代码出现问题:

你能不能请帮助?





Hi guys , I am trying to make the label on my windows form project count the number of characters that are entered in the richTextbox .. something is wrong with my code below:
can you please help?


  public int WordCount(RichTextBox rtb)
        {

            if (rtb.Text.Equals(""))
            {
                return 0;

            }

            else
            {
                string[] sWords = rtb.Text.Split(' ');

                int iWords = sWords.Length;
                return iWords;

            }


            }
    
            private void label1_Click(object sender, EventArgs e)
            {

            label1.Text = Convert.ToString(WordCount(rtbText));

        }
    }
}

推荐答案

rtbText 应为 rtb.Text rtb



/ ravi
rtbText should be rtb.Text rtb.

/ravi


谢谢你们我现在已经解决了,它就像这样简单:





Thank You guys I have solved it now, it was just as easy as this:


private void richTextBox1_TextChanged(object sender, EventArgs e)
       {
           label1.Text = richTextBox1.Text.Length.ToString();
       }


这篇关于有些人可以帮我提一下标签字数请用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆