[英]WinForm Text Control that displays current character/character limit
I need a way to display, like you see in some web apps, the current characters/character limit for a Text Control
( ie 3/500). 我需要一种显示方式,就像您在某些Web应用程序中看到的那样,显示
Text Control
的当前字符/字符数限制 ( 即 3/500)。 I usually see this as a label
residing directly above or below the Text Control
. 我通常将其视为直接位于
Text Control
上方或下方的label
。
How is this 'normally' accomplished? “正常”如何完成? Should I override my
Text Control
somehow? 我应该以某种方式覆盖我的
Text Control
吗? Do I just manually add labels by every Text Control
and ' bind
' them to properties of the Text Control
? 我是否只是通过每个
Text Control
手动添加标签并将它们“ bind
”到Text Control
属性? Do I need to create a composite control that has the T ext Control
& Label Controls
together to accomplish what I need? 我是否需要创建一个同时包含“
ext Control
和“ Label Controls
的复合Label Controls
来完成我所需要的?
Any direction or help will be greatly appreciated. 任何方向或帮助将不胜感激。
Attach a handler to TextBox.TextChanged
and refresh the label based on TextBox.Text.Length
and the maximum size you want to allow. 将处理程序附加到
TextBox.TextChanged
并根据TextBox.Text.Length
和要允许的最大大小刷新标签。 You can also enforce the limit in the same handler by calling TextBox.Text = TextBox.Text.Substring( 0, maxChars );
您还可以通过调用
TextBox.Text = TextBox.Text.Substring( 0, maxChars );
在同一处理程序中实施限制TextBox.Text = TextBox.Text.Substring( 0, maxChars );
. 。
int maxChars = 100;
Textbox onKeyUp:
remainingChars.Text = Convert.ToString(maxChars - textbox.Text.Length);
Stick it in a function: 将其粘贴在一个函数中:
getRemainingChars(TextBox tb, Label lbl, int max)
{
lbl.Text = Convert.ToString(max - tb.Text.Length) + "/" + Convert.ToString(max);
}
Hopefully thats of some help 希望这能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.