469,609 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

AutoScroll returning to 0,0 somewhere around focus

Not having much luck tracking this down...

I'm working with a form, Form1, which contains a panel called pnlParent.
Both Form1 and pnlParent have AutoScroll = False.

pnlParent contains a panel called pnlScroller. pnlScroller.AutoScroll =
True. Finally, pnlScroller contains a custom control I wrote (in which I
override OnPaint & paint entirely custom, if that matters). So in summary
there are 4 controls with the following parent/child heiarchy:

Form1 -> pnlParent -> pnlScroller (autoscrolls) -> myControl (custom
painted)

myControl is always bigger in dimensions than pnlScroller, so pnlScroller
always shows both vertical and horizontal scrollbars. At run time, if I
grab either of pnlScroller's scrollbars & move it anywhere, I can scroll
over myControl and it works as I would expect to "scroll over" myControl.
If I then "click away" from Form1 (say, to the desktop) so that Form1 looses
Focus, the scroll bars on pnlScroller remain where I left them.

However, clicking back (or, Alt+Tab) onto on to Form1 so that it regains
Focus causes the scrollbars on pnlScroller to both return to 0,0. This is
an undesired feature of my application, because I want pnlScroller's scroll
bars to remain stationary unless the user scrolls them (I do not want
application focus to alter the scroll position). I do not have any code in
the application that programatically sets the scroll position.

I have tried to trap where this is happening in some of the obvious places,
like Form1.GotFocus, Form1.Activated and pnlScroller.GotFocus but by the
time these events have fired, the scrollbars have already 'adjusted'
themselves to 0,0. Any advice on where I can set a trap to catch this as it
is happening? I believe that pnlScroller is attempting to perform some
logic where it tries to "fit" myControl into it's viewable area and the
scrolling to position 0,0 in an artifact of this attempt. But since this is
an impossible task (because myControl is always larger than pnlScroller), I
want to supress this behavior some how.
Nov 21 '05 #1
1 1796
"Workgroups" <no*****@domainless.com> schrieb
Not having much luck tracking this down...

I'm working with a form, Form1, which contains a panel called
pnlParent. Both Form1 and pnlParent have AutoScroll = False.

pnlParent contains a panel called pnlScroller. pnlScroller.AutoScroll =
True. Finally, pnlScroller contains a
custom control I wrote (in which I override OnPaint & paint entirely
custom, if that matters). So in summary there are 4 controls with
the following parent/child heiarchy:

Form1 -> pnlParent -> pnlScroller (autoscrolls) -> myControl (custom
painted)

myControl is always bigger in dimensions than pnlScroller, so
pnlScroller always shows both vertical and horizontal scrollbars. At run
time, if I grab either of pnlScroller's scrollbars & move it
anywhere, I can scroll over myControl and it works as I would expect
to "scroll over" myControl. If I then "click away" from Form1 (say,
to the desktop) so that Form1 looses Focus, the scroll bars on
pnlScroller remain where I left them.

However, clicking back (or, Alt+Tab) onto on to Form1 so that it
regains Focus causes the scrollbars on pnlScroller to both return to
0,0. This is an undesired feature of my application, because I want
pnlScroller's scroll bars to remain stationary unless the user
scrolls them (I do not want application focus to alter the scroll
position). I do not have any code in the application that programatically
sets the scroll position.

I have tried to trap where this is happening in some of the obvious
places, like Form1.GotFocus, Form1.Activated and
pnlScroller.GotFocus but by the time these events have fired, the
scrollbars have already 'adjusted' themselves to 0,0. Any advice on
where I can set a trap to catch this as it is happening? I believe
that pnlScroller is attempting to perform some logic where it tries
to "fit" myControl into it's viewable area and the scrolling to
position 0,0 in an artifact of this attempt. But since this is an
impossible task (because myControl is always larger than
pnlScroller), I want to supress this behavior some how.

I can reproduce this. I took a Button instead of a Usercontrol for
simplification - no difference. After debugging it seems that the method
ScrollControlIntoView is called whenever the control gets the focus.

Whenever the form is activated, it focusses it's active control. This is the
button. The button, when getting the focus, checks whether it is contained
by an instance of 'ContainerControl'. If it is, it calls it's Container's
method to activate the active control. This includes calling
ScrollControlIntoView.

Unfortunately I don't have a solution. I didn't find where to hook into this
process, but based on this information maybe you (or somebody else) can find
one on your own.
Armin

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Alexander Brown | last post: by
reply views Thread by rawCoder | last post: by
reply views Thread by 23s | last post: by
4 posts views Thread by Sam | last post: by
6 posts views Thread by student1976 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.