Why do TextBoxes have a TextLength property? Does it offer any advantages over getting the Text’s Length through Text.Length?
Why do TextBoxes have a TextLength property? Does it offer any advantages over getting
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Behind this WinForms control is a Win32 edit control.
The Win32 edit control exposes its text through the
WM_GETTEXTLENGTHandWM_GETTEXTmessages. You need to sendWM_GETTEXTLENGTHfirst so that you know how big a buffer to allocate. Then you can sendWM_GETTEXTto populate the buffer.If you just want the length of the text you can obtain it without allocating a buffer by sending just the
WM_GETTEXTLENGTHmessage.The .net control is simply reflecting this underlying control’s behaviour. For a multi-line control with a lot of text, being able to obtain the text length without having to allocate and populate the buffer could be a very useful for performance.