Why do TextBoxes have a TextLength property? Does it offer any advantages over getting the Text's Length through Text.Length?
Behind this WinForms control is a Win32 edit control.
The Win32 edit control exposes its text through the WM_GETTEXTLENGTH
and WM_GETTEXT
messages. You need to send WM_GETTEXTLENGTH
first so that you know how big a buffer to allocate. Then you can send WM_GETTEXT
to 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_GETTEXTLENGTH
message.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With