using System; using System.Drawing; using System.Collections; using System.Windows.Forms; namespace FuzzyQuotient { /// <summary> /// Summary description for AutoScrollPanel. /// </summary> public class AutoScrollPanel : Panel { public Panel Contents { get { return contents; } } Panel contents; VScrollBar vScroll; public AutoScrollPanel() { // create a scroll bar this.vScroll = new VScrollBar(); this.vScroll.Parent = this; this.vScroll.Visible = true; this.vScroll.Minimum = 0; this.vScroll.SmallChange = 20; this.vScroll.ValueChanged += new EventHandler (this.scrollbar_ValueChanged); // create the contents panel that holds the controls to be scrolled this.contents = new Panel(); this.contents.Parent = this; this.contents.Width = this.ClientSize.Width - this.vScroll.Size.Width; } private void scrollbar_ValueChanged (object o, EventArgs e) { if (o == this.vScroll) { //By decreasing the top y coordinate //the contents panel appears to scroll this.contents.Top = -this.vScroll.Value; this.Update(); } } void CheckScrollBars() { this.vScroll.Visible = this.contents.Size.Height > this.ClientSize.Height; } protected override void OnResize (EventArgs e) { this.contents.Width = this.ClientSize.Width - this.vScroll.Size.Width; this.vScroll.Bounds = new Rectangle (this.ClientSize.Width - this.vScroll.Size.Width, 0, this.vScroll.Size.Width, this.ClientSize.Height); if (this.ClientSize.Height >= 0) this.vScroll.LargeChange = this.ClientSize.Height; CheckScrollBars(); } public void SetScrollHeight(int height) { this.contents.Height = height; this.vScroll.Maximum = this.contents.Size.Height; CheckScrollBars(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)