使我在文本框中的字符只包含少于5个字符。 [英] make my char in textbox only contain less 5 char.

查看:118
本文介绍了使我在文本框中的字符只包含少于5个字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello codeproject。

i需要帮助解决我的问题。

假设我有textbox1.text,每隔5秒接收一个包含100个字符的字符串。

但是如何使我的char只能包含少于5个char的char?如何自动删除95休息char?我使用了maxlength但仍然没有工作文本框仍然收到100个字符。

解决方案

MaxLength属性仅在文本输入TextBox时适用。



当您以编程方式添加文本时,您需要自己截断文本



例如

  Dim  s  As  字符串 =   1234567946544 
.TextBox1.Text = s.Substring( 0 4


Hello codeproject.
i need help to solve my problem.
assumming i have textbox1.text that every 5 second receive string that contain 100 char.
but how to make my char only can contains char less than five char? how to auto delete 95 rest char? i was used maxlength but still not working the textbox still receive 100 char.

解决方案

The MaxLength property only applies when text is typed into the TextBox.

As you are adding the text programmatically you will need to truncate the text yourself

For example

Dim s As String = "1234567946544"
        Me.TextBox1.Text = s.Substring(0, 4)


这篇关于使我在文本框中的字符只包含少于5个字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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