Thursday, April 28, 2005

My first and second .Net complaint

I'm just learning the .Net framework but already I'm starting to see some problems. Take for example the text selection API on the text controls. There are two methods for working on the selection:



SelectionStart - gets and sets the starting offset.

SelectionLength - gets and sets the length of the selection.



The problem is that given these methods there's no way to control the position of the caret. These methods always place the caret at the end of the selection. The low level windows API EM_SETSEL was smarter. With it you specified a start offset and end offset, where the start offset could be greater than the end offset, thus allowing you to position the caret at the start of the selection.


The only solution I could come up with to work around this issue in .Net was to actually send the low level EM_ message to the control. Which brings me to my second .Net complaint. Given that access to the legacy message based API is often needed, it would be nice if .Net provided a built in legacy access API with message constants and structure predefined. The way it works now, you need to declare the extern for SendMessage, lookup the message IDs from winuser.h and declare your own constants.

Post a Comment
 
The Out Campaign: Scarlet Letter of Atheism