I haven't finished it yet, but I was banging one out for something.
Here's the code thus far. You're responsible for drawing your controls
on, and resizing, DataPane yourself. The container should do the rest.
//<CODE>
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ScrollPanel {
public delegate void ResetClickHandler( object sender, EventArgs e );
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class ScrollPane : System.Windows.Forms.UserControl {
public event ResetClickHandler ResetClicked;
public enum ResetButtonBehaviors {
Normal=0,
Hidden=1,
Disabled=2
}
private const int SCROLL_THICKNESS = 16;
private const int EDGE_PADDING = 2;
private ResetButtonBehaviors pResetButtonBehavior =
ResetButtonBehaviors.Normal;
private System.Windows.Forms.PictureBox pbContainer;
private System.Windows.Forms.Button btnReset;
private System.Windows.Forms.VScrollBar vScroller;
private System.Windows.Forms.HScrollBar hScroller;
private System.Windows.Forms.PictureBox ViewPort;
private System.Windows.Forms.PictureBox DataPane;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ScrollPane() {
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing ) {
if( disposing ) {
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pbContainer = new System.Windows.Forms.PictureBox();
this.btnReset = new System.Windows.Forms.Button();
this.vScroller = new System.Windows.Forms.VScrollBar();
this.hScroller = new System.Windows.Forms.HScrollBar();
this.ViewPort = new System.Windows.Forms.PictureBox();
this.DataPane = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pbContainer
//
this.pbContainer.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D;
this.pbContainer.Name = "pbContainer";
this.pbContainer.Size = new System.Drawing.Size(448, 448);
this.pbContainer.TabIndex = 0;
this.pbContainer.TabStop = false;
//
// btnReset
//
this.btnReset.Location = new System.Drawing.Point(430, 430);
this.btnReset.Name = "btnReset";
this.btnReset.Size = new System.Drawing.Size(16, 16);
this.btnReset.TabIndex = 7;
this.btnReset.TabStop = false;
this.btnReset.Text = ".";
this.btnReset.Click += new
System.EventHandler(this.btnReset_Click);
//
// vScroller
//
this.vScroller.LargeChange = 100;
this.vScroller.Location = new System.Drawing.Point(429, 4);
this.vScroller.Name = "vScroller";
this.vScroller.Size = new System.Drawing.Size(16, 424);
this.vScroller.TabIndex = 6;
this.vScroller.Scroll += new
System.Windows.Forms.ScrollEventHandler(this.vScroller_Scroll);
//
// hScroller
//
this.hScroller.LargeChange = 100;
this.hScroller.Location = new System.Drawing.Point(5, 430);
this.hScroller.Name = "hScroller";
this.hScroller.Size = new System.Drawing.Size(423, 16);
this.hScroller.TabIndex = 5;
this.hScroller.Scroll += new
System.Windows.Forms.ScrollEventHandler(this.hScroller_Scroll);
//
// ViewPort
//
this.ViewPort.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D;
this.ViewPort.Location = new System.Drawing.Point(2, 2);
this.ViewPort.Name = "ViewPort";
this.ViewPort.Size = new System.Drawing.Size(418, 422);
this.ViewPort.TabIndex = 8;
this.ViewPort.TabStop = false;
//
// DataPane
//
this.DataPane.Location = new System.Drawing.Point(4, 4);
this.DataPane.Name = "DataPane";
this.DataPane.Size = new System.Drawing.Size(52, 56);
this.DataPane.TabIndex = 9;
this.DataPane.TabStop = false;
//
// ScrollPane
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.DataPane,
this.ViewPort,
this.btnReset,
this.vScroller,
this.hScroller,
this.pbContainer});
this.Name = "ScrollPane";
this.Size = new System.Drawing.Size(450, 450);
this.Resize += new System.EventHandler(this.ScrollPane_Resize);
this.ResumeLayout(false);
}
#endregion
private void ScrollPane_Resize(object sender, System.EventArgs e) {
DataPane.Parent = ViewPort;
pbContainer.Location = new Point( 0, 0 );
pbContainer.Size = new Size( this.Width, this.Height );
hScroller.Location = new Point( EDGE_PADDING, pbContainer.Height -
(EDGE_PADDING + SCROLL_THICKNESS) );
hScroller.Size = new Size( pbContainer.Width - ( (EDGE_PADDING*2) +
SCROLL_THICKNESS), SCROLL_THICKNESS );
vScroller.Location = new Point( pbContainer.Width - (EDGE_PADDING +
SCROLL_THICKNESS), EDGE_PADDING );
vScroller.Size = new Size( SCROLL_THICKNESS, pbContainer.Height - (
(EDGE_PADDING*2) + SCROLL_THICKNESS ) );
btnReset.Size = new Size( SCROLL_THICKNESS, SCROLL_THICKNESS );
btnReset.Location = new Point( pbContainer.Width - (EDGE_PADDING +
SCROLL_THICKNESS), pbContainer.Height - (EDGE_PADDING +
SCROLL_THICKNESS) );
ViewPort.Parent = pbContainer;
ViewPort.Location = new Point( 0, 0 );
ViewPort.Size = new Size( pbContainer.Width - ((EDGE_PADDING*2) +
SCROLL_THICKNESS), pbContainer.Height - ((EDGE_PADDING*2) +
SCROLL_THICKNESS ) );
CalculateScrollbars();
}
private void CalculateScrollbars(){
hScroller.Enabled = ( DataPane.Width > ViewPort.Width );
if( hScroller.Enabled ){
hScroller.Maximum = (DataPane.Width - ViewPort.Width)+120;
hScroller.Minimum = 0;
}
vScroller.Enabled = ( DataPane.Height > ViewPort.Height );
if( vScroller.Enabled ){
vScroller.Maximum = (DataPane.Height - ViewPort.Height)+120;
vScroller.Minimum = 0;
}
}
private void SetButtonBehavior( ResetButtonBehaviors behavior ){
switch( behavior ){
case ResetButtonBehaviors.Normal:
btnReset.Enabled = true;
btnReset.Visible = true;
break;
case ResetButtonBehaviors.Hidden:
btnReset.Visible = false;
btnReset.Enabled = true;
break;
case ResetButtonBehaviors.Disabled:
btnReset.Visible = true;
btnReset.Enabled = false;
break;
}
}
private void btnReset_Click(object sender, System.EventArgs e) {
if( ResetClicked != null ){
ResetClicked( btnReset, e );
}
}
private void vScroller_Scroll(object sender,
System.Windows.Forms.ScrollEventArgs e) {
int val = vScroller.Value;
DataPane.Top = (-1 * val)+1;
}
private void hScroller_Scroll(object sender,
System.Windows.Forms.ScrollEventArgs e) {
int val = hScroller.Value;
DataPane.Left = (-1 * val)+1;
}
public ResetButtonBehaviors ResetButtonBehavior{
get{
return pResetButtonBehavior;
}
set{
pResetButtonBehavior = value;
SetButtonBehavior( pResetButtonBehavior );
}
}
public PictureBox DataPanel {
get{
return this.DataPane;
}
}
public Size DataPaneSize {
get{
return DataPane.Size;
}
set{
DataPane.Size = value;
CalculateScrollbars();
}
}
}
}
//</CODE>