开发者

Character count using cursor in C#

I am attempting to count the characters in a text area using the cursor in C#. For example, I have a string of characters in the text area: "Please count my characters". If I highlight " charact开发者_如何学Cers", it should tell me that it has 11 characters including the whitespace.

Thanks who viewed and answered my inquiry.


In Winforms, just call textbox.SelectedText.Length. Same goes for WPF


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

EDIT:

for textboxes use this but I will prefer using richTextbox

textBox1.SelectionLength.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜