Monday, August 22, 2005

Autoscrolling Panel Bug

The current implementation of the Panel control contains a bug in the autoscrolling code. Whenever the panel control gets the focus it will scroll the active subcontrol in to view. This bug is acknowledged by Microsoft but, because it is “previously shipped behavior”, it will not be resolved in the next Whidbey release :-(

See also: Bug Details: AutoScroll positon gets losted

Overriding this behavior was not easy as a lot of methods involved in the autoscrolling are not virtual. After some hacking we found a “workaround” for the bug by always scrolling to the current position, which effectively does nothing.

public class MyPanel : Panel
    protected override Point ScrollToControl(Control PobjActiveControl)
        return AutoScrollPosition;

This however not only disables the bug behavior but almost all the autoscrolling behavior too. Therefore the desired autoscrolling behavior, for instance when the user tabs through the panel’s subcontrols, has to be coded manually. Luckily for my project this was already in place althought it only requires a few lines of code to accomplish.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?