Solved

Scroll the scrollbar of the panel automaically

Posted on 2007-03-27
6
982 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

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 86

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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