如何将TextBox的MaxLength设置为Infinite?

时间:2014-05-26 20:13:21

标签: c# winforms

默认情况下,MaxLength的值为32676。如何将此值设置为无限制或无限?

2 个答案:

答案 0 :(得分:3)

您可以将其设为0。来自documentation on MaxLength

  

Windows NT 4.0,Windows 2000,Windows 2000 Professional,Windows 2000 Server,Windows 2000 Advanced Server,Windows XP Home Edition,Windows XP Professional x64 Edition,Windows Server 2003平台注意:如果MaxLength property设置为0,用户可以输入的最大字符数为2147483646或基于可用内存的数量,以较小者为准。

     

Windows Millennium Edition平台注意:如果MaxLength属性设置为0,则用户可以输入的最大字符数为32,766或基于可用内存的数量,以较小者为准。

因此,虽然无限可能,但略多于20亿个字符应该足够。

答案 1 :(得分:1)

(假设WinForms TextBox)由于MaxLengthInt32,您只能将其带到Int32.MaxValue

实际上那很多(2,147,483,647)。你真的需要它无限吗?那么你最好使用一个自定义控件(当然,你可以从现有控制中获得一个)。