Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why .Net textboxes have TextLength vs Text.Length?

Why do TextBoxes have a TextLength property? Does it offer any advantages over getting the Text's Length through Text.Length?

like image 436
Corey Ogburn Avatar asked May 27 '11 15:05

Corey Ogburn


1 Answers

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.

like image 65
David Heffernan Avatar answered Nov 06 '22 18:11

David Heffernan