PC Review


Reply
Thread Tools Rate Thread

AutoScroll returning to 0,0 somewhere around focus

 
 
Workgroups
Guest
Posts: n/a
 
      5th Aug 2005
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.


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      5th Aug 2005
"Workgroups" <(E-Mail Removed)> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to have DataGrid AutoScroll without stealing the focus ? =?Utf-8?B?U2hhcm9u?= Microsoft C# .NET 21 14th Feb 2006 05:49 AM
Autoscroll scrollbar thumb position being reset upon focus change =?Utf-8?B?ZGx5bGU=?= Microsoft Dot NET Framework Forms 1 15th Jul 2005 04:44 PM
Disabling Scroll-to-Focus with AutoScroll Ian Durkan via .NET 247 Microsoft Dot NET Framework Forms 0 15th Sep 2004 07:43 PM
AutoScroll, Lost Focus - Scroll Into View Jonathan Microsoft Dot NET Framework Forms 0 8th Apr 2004 12:56 AM
Returning Key Focus Dan Gesshel Microsoft Excel Programming 1 5th Sep 2003 07:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:52 AM.