Monday, December 08, 2008

The buggy .net framework 2.0

I've been using the .net framework for years, my work didn't involved with the UI development for the most time, right now I'm developing a game editor for our game, in the months developing, I found some problems about the framework, and I'm sure they are bugs, I didn't tried them on .net framework 3.5, I don't know if these bugs have been resolved.

1st bug, the framework handles the shortcut keys incorrectly.
Associate a context menu strip to a control like TextBox, or place a MainMenuStrip on the form will take the same effect, make sure there is a menu item which have a shortcut key that could get conflicted with the textbox, like a Delete key. ok, run the program and press the key like Delete, you will find the key takes no effects in the control, this is a big problem that can not be ignored, you never need a standard text box that can only use Backspace but not the Delete key(if you have a shortcut with Backspace, you will only able to remove characters by using mouse's context menu), this problem quite sucks.
Hack Solution: Uses reflection to retrieve the FieldInfo shortcuts in type ToolStrip, overrides the control or the form's ProcessCmdKey, use the FieldInfo to access the private field of the context menu strip or main menu strip, it is a System.Collections.HashTable, if the hash table contains the shortcut(you need cast the wParam to type Keys), resend the message to the control that you wish to recieve the message.


2nd bug, the ScrollableControl resets the scrollbars' position when they get the focus again.
This bug happens if a ScrollableControl like Panel contains a child control which size is larger than the container and the ScrollableControl have AutoScroll assigned to true. If the ScrollbarControl have the none zero scrollbar's position, either the horizontal scrollbar or the vertical scrollbar, when it gains the focus, both the horizontal and vertical scrollbar's position will reset to zero.
Hack Solution: A really damn shit way to solve this, back up the AutoScrollPosition value of the ScrollableControl when the child control lost focus, when the child control gains the focus again, multiply the X and Y of the backed up value with -1, assign the result to the AutoScrollPosition.