Solved

Scroll the scrollbar of the panel automaically

Posted on 2007-03-27
6
970 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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