Solved

Scroll the scrollbar of the panel automaically

Posted on 2007-03-27
6
978 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
Technology Partners: 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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