Solved

Scroll the scrollbar of the panel automaically

Posted on 2007-03-27
6
966 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

9 Experts available now in Live!

Get 1:1 Help Now