Solved

Scroll the scrollbar of the panel automaically

Posted on 2007-03-27
6
968 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:alenwong
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:mzalewski
ID: 18803575
You would need to use javascript to achieve this:

You can set the panel's scrollTop property:
[Javascript]
document.getElementById('<%=panel.ClientID%>').scrollTop = newposition;
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18803830
WinForms or WebForms?

Is there by chance a control in the Panel that you want to scroll to?
0
 

Author Comment

by:alenwong
ID: 18806029
My Programming Language is c#, and I am using Visual Studio 2005 and .NET Framework 2.0, thanks
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18808388
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
0
 

Author Comment

by:alenwong
ID: 18821826
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,
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18823859
Something like...

        private void button1_Click(object sender, EventArgs e)
        {
            ScrollPanel(panel1, 50, 50);
        }

        private void ScrollPanel(Panel pnl, int xPct, int yPct)
        {
            double xFct = Convert.ToDouble(xPct) / Convert.ToDouble(100);
            double yFct = Convert.ToDouble(yPct) / Convert.ToDouble(100);
            pnl.HorizontalScroll.Value = Convert.ToInt32(pnl.HorizontalScroll.Maximum * xFct);
            pnl.VerticalScroll.Value = Convert.ToInt32(pnl.VerticalScroll.Maximum * yFct);
            // don't ask me why...if you just set them like above...
            // ONLY ONE of the scrollbars gets updated on the screen.
            // so I repeated the code below and both scrollbars get updated...   =\
            pnl.HorizontalScroll.Value = Convert.ToInt32(pnl.HorizontalScroll.Maximum * xFct);
            pnl.VerticalScroll.Value = Convert.ToInt32(pnl.VerticalScroll.Maximum * yFct);
        }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now