Link to home
Start Free TrialLog in
Avatar of alenwong
alenwong

asked on

Scroll the scrollbar of the panel automaically

Hi experts,

I'd like to know how to scroll programically the scrollbar of a panel. The panel contains a very long panorama in which I would like the panel to programmically scroll to particular location when user clicks a button. Thanks in advance.
Avatar of mzalewski
mzalewski

You would need to use javascript to achieve this:

You can set the panel's scrollTop property:
[Javascript]
document.getElementById('<%=panel.ClientID%>').scrollTop = newposition;
Avatar of Mike Tomlinson
WinForms or WebForms?

Is there by chance a control in the Panel that you want to scroll to?
Avatar of alenwong

ASKER

My Programming Language is c#, and I am using Visual Studio 2005 and .NET Framework 2.0, thanks
Still not enough info.

Windows application?
or Web application?

Do you just want the scrollbar to move down?

Or do you want to move it so that a particular control is in view?

Or do you want to move it to xxx percentage of the way down?

You might want ScrollableControl.ScrollControlIntoView():
http://msdn2.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.scrollcontrolintoview(VS.80).aspx

    panel1.ScrollControlIntoView(label1);

Or you can use the SendMessage() API with WM_VSCROLL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/scrollbars/scrollbarreference/scrollbarmessages/wm_vscroll.asp
An example:
http://weblogs.asp.net/israelio/archive/2004/07/20/188664.aspx
It is a Windows Application

I am displaying a image in a picturebox control which is in a panel control. The height of the picturebox was fixed within the panel (so vertical scolling is not needed anyhow), the width of the picturebox will scale according to the ratio of the height of the image to the height of the picturebox, and the image will fit in the size-adjusted picturebox so that horizontal scrolling may required if the width of picturebox is larger than the width of panel.

I would like to know how to scroll the panel xxx percentage of the way to the right by coding. The value would be generated by other part of the program each time so there is no fixed value.

Thanks in advance


based on scale between the height of the picturebox and the image,
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial