/* ScrollPanel This example demonstrates the use of "panel within a panel scrolling" technique. There are 3 panels: trackPanel, scrollPanel, and drawPanel. trackPanel holds 3 TrackBars tha set an rgb currentColor. scrollPanel holds the drawPanel and is autoscrollable. drawPanel is larger than scrollPanel and is used to draw rectangles in the currentColor. This file was created using Visual Studio .NET 2003 Designer. Mike Barnes 10/4/04 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace scrollPanel { /// /// Summary description for ScrollablePanel. /// public class ScrollablePanel : System.Windows.Forms.Form { private System.Windows.Forms.TrackBar redTrack; private System.Windows.Forms.TrackBar greenTrack; private System.Windows.Forms.TrackBar blueTrack; private Color currentColor; private System.Windows.Forms.Panel scrollPanel; private System.Windows.Forms.Panel drawPanel; private System.Windows.Forms.Panel trackPanel; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public ScrollablePanel() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // currentColor = Color.Black; drawPanel.Parent = scrollPanel; scrollPanel.Parent = this; redTrack.Value = greenTrack.Value = blueTrack.Value = 125; } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.scrollPanel = new System.Windows.Forms.Panel(); this.redTrack = new System.Windows.Forms.TrackBar(); this.greenTrack = new System.Windows.Forms.TrackBar(); this.blueTrack = new System.Windows.Forms.TrackBar(); this.trackPanel = new System.Windows.Forms.Panel(); this.drawPanel = new System.Windows.Forms.Panel(); this.scrollPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.redTrack)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.greenTrack)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.blueTrack)).BeginInit(); this.trackPanel.SuspendLayout(); this.SuspendLayout(); // // scrollPanel // this.scrollPanel.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.scrollPanel.AutoScroll = true; this.scrollPanel.AutoScrollMargin = new System.Drawing.Size(20, 20); this.scrollPanel.AutoScrollMinSize = new System.Drawing.Size(500, 500); this.scrollPanel.BackColor = System.Drawing.Color.White; this.scrollPanel.Controls.Add(this.drawPanel); this.scrollPanel.DockPadding.Bottom = 30; this.scrollPanel.DockPadding.Right = 30; this.scrollPanel.Location = new System.Drawing.Point(130, 10); this.scrollPanel.Name = "scrollPanel"; this.scrollPanel.Size = new System.Drawing.Size(374, 290); this.scrollPanel.TabIndex = 0; // // redTrack // this.redTrack.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.redTrack.BackColor = System.Drawing.Color.Red; this.redTrack.LargeChange = 32; this.redTrack.Location = new System.Drawing.Point(0, 0); this.redTrack.Maximum = 255; this.redTrack.Name = "redTrack"; this.redTrack.Orientation = System.Windows.Forms.Orientation.Vertical; this.redTrack.Size = new System.Drawing.Size(42, 312); this.redTrack.TabIndex = 2; this.redTrack.TickStyle = System.Windows.Forms.TickStyle.None; this.redTrack.ValueChanged += new System.EventHandler(this.trackBarValueChanged); // // greenTrack // this.greenTrack.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.greenTrack.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0))); this.greenTrack.Location = new System.Drawing.Point(40, 0); this.greenTrack.Maximum = 255; this.greenTrack.Name = "greenTrack"; this.greenTrack.Orientation = System.Windows.Forms.Orientation.Vertical; this.greenTrack.Size = new System.Drawing.Size(42, 312); this.greenTrack.TabIndex = 3; this.greenTrack.TickStyle = System.Windows.Forms.TickStyle.None; this.greenTrack.ValueChanged += new System.EventHandler(this.trackBarValueChanged); // // blueTrack // this.blueTrack.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.blueTrack.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192))); this.blueTrack.Location = new System.Drawing.Point(80, 0); this.blueTrack.Maximum = 255; this.blueTrack.Name = "blueTrack"; this.blueTrack.Orientation = System.Windows.Forms.Orientation.Vertical; this.blueTrack.Size = new System.Drawing.Size(42, 312); this.blueTrack.TabIndex = 4; this.blueTrack.TickStyle = System.Windows.Forms.TickStyle.None; this.blueTrack.ValueChanged += new System.EventHandler(this.trackBarValueChanged); // // trackPanel // this.trackPanel.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.trackPanel.Controls.Add(this.blueTrack); this.trackPanel.Controls.Add(this.greenTrack); this.trackPanel.Controls.Add(this.redTrack); this.trackPanel.Location = new System.Drawing.Point(0, 0); this.trackPanel.Name = "trackPanel"; this.trackPanel.Size = new System.Drawing.Size(128, 312); this.trackPanel.TabIndex = 5; // // drawPanel // this.drawPanel.Location = new System.Drawing.Point(0, 0); this.drawPanel.Name = "drawPanel"; this.drawPanel.Size = new System.Drawing.Size(800, 800); this.drawPanel.TabIndex = 0; this.drawPanel.MouseUp += new System.Windows.Forms.MouseEventHandler(this.setPoint); // // ScrollablePanel // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(512, 309); this.Controls.Add(this.trackPanel); this.Controls.Add(this.scrollPanel); this.Name = "ScrollablePanel"; this.Text = "Scrollable Panel"; this.scrollPanel.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.redTrack)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.greenTrack)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.blueTrack)).EndInit(); this.trackPanel.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new ScrollablePanel()); } private void setPoint(object sender, System.Windows.Forms.MouseEventArgs e) { Graphics g = drawPanel.CreateGraphics(); g.FillRectangle(new SolidBrush(currentColor), e.X, e.Y, e.X + 2, e.Y + 2); g.Dispose(); } private void trackBarValueChanged(object sender, System.EventArgs e) { redTrack.BackColor = Color.FromArgb(redTrack.Value, 0, 0); greenTrack.BackColor = Color.FromArgb(0, greenTrack.Value, 0); blueTrack.BackColor = Color.FromArgb(0, 0, blueTrack.Value); currentColor = Color.FromArgb(redTrack.Value, greenTrack.Value, blueTrack.Value); } } }