The text box is disabled with a huge string

I have a problem with textbox when it typed a huge line.

In my case, the text box is used to write email addresses, and it has no character limit. So, I did this test: I wrote 200 email addresses in a notebook, and I pasted the text into the textbox and the text disappeared, but if I focus the focus of the control, the text will be displayed again. I already saw this link, but it didn’t help me. I already tried to change the MaxLength property to 0 ( as Microsoft recommends doing ), but it does not work either.

Given an email address with 50 characters, the MaxLength property will not be a problem, because 200 email addresses multiplied by 50 characters (each email address), I will have 10,000 characters, and the default value of TextBox.MaxLength is 32767.

And, before you request the code, I only set the text to a string.

myEmailObject.Address = txtEmail.Text;

Should I use RichText , or what?

+2
source share
2 answers

Try setting the Multiline property to True and increase the height of the text field.

+4
source

This is a well-known limitation in the Windows EDIT control, a built-in control that is completed by the TextBox class. I know that the limitation is present in Windows 7 SP1 and Windows 8, earlier versions almost certainly have it.

You will use this limit if more than 5000 characters are displayed in a single line text box. Give or take, it is based on the total width in pixels of the displayed text. That way you can fit a lot more when using a smaller font or have a lot more i than W characters. Afaik, you will overcome the limit when the width exceeds 32767 pixels, a number that appears in several places in the USER32 api and dates from versions of Windows and lt = 3, which were 16-bit. Maintaining EDIT interoperability in major releases for 30 years has been a major effort.

This limit is not very often put to the test, typing the fact that a lot of characters in a single-line text field are impractical. There is no sensible way for the user to do anything useful with such text in such a small space. It is impossible to read this, reliable editing, of course, is out of the question.

Consider a more practical and convenient user interface; limiting simply ceases to be a problem. Use Multiline = true or just display the line holder for the place where the ellipsis is used.

+8
source

Source: https://habr.com/ru/post/1202007/


All Articles