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.Collecti ons;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Windows. Forms;
namespace ScrollPanel {
public delegate void ResetClickHandl er( object sender, EventArgs e );
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class ScrollPane : System.Windows. Forms.UserContr ol {
public event ResetClickHandl er ResetClicked;
public enum ResetButtonBeha viors {
Normal=0,
Hidden=1,
Disabled=2
}
private const int SCROLL_THICKNES S = 16;
private const int EDGE_PADDING = 2;
private ResetButtonBeha viors pResetButtonBeh avior =
ResetButtonBeha viors.Normal;
private System.Windows. Forms.PictureBo x pbContainer;
private System.Windows. Forms.Button btnReset;
private System.Windows. Forms.VScrollBa r vScroller;
private System.Windows. Forms.HScrollBa r hScroller;
private System.Windows. Forms.PictureBo x ViewPort;
private System.Windows. Forms.PictureBo x DataPane;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
public ScrollPane() {
// This call is required by the Windows.Forms Form Designer.
InitializeCompo nent();
// 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.Disp ose();
}
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 InitializeCompo nent()
{
this.pbContaine r = new System.Windows. Forms.PictureBo x();
this.btnReset = new System.Windows. Forms.Button();
this.vScroller = new System.Windows. Forms.VScrollBa r();
this.hScroller = new System.Windows. Forms.HScrollBa r();
this.ViewPort = new System.Windows. Forms.PictureBo x();
this.DataPane = new System.Windows. Forms.PictureBo x();
this.SuspendLay out();
//
// pbContainer
//
this.pbContaine r.BorderStyle =
System.Windows. Forms.BorderSty le.Fixed3D;
this.pbContaine r.Name = "pbContaine r";
this.pbContaine r.Size = new System.Drawing. Size(448, 448);
this.pbContaine r.TabIndex = 0;
this.pbContaine r.TabStop = false;
//
// btnReset
//
this.btnReset.L ocation = new System.Drawing. Point(430, 430);
this.btnReset.N ame = "btnReset";
this.btnReset.S ize = new System.Drawing. Size(16, 16);
this.btnReset.T abIndex = 7;
this.btnReset.T abStop = false;
this.btnReset.T ext = ".";
this.btnReset.C lick += new
System.EventHan dler(this.btnRe set_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.ScrollEve ntHandler(this. vScroller_Scrol l);
//
// 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.ScrollEve ntHandler(this. hScroller_Scrol l);
//
// ViewPort
//
this.ViewPort.B orderStyle =
System.Windows. Forms.BorderSty le.Fixed3D;
this.ViewPort.L ocation = new System.Drawing. Point(2, 2);
this.ViewPort.N ame = "ViewPort";
this.ViewPort.S ize = new System.Drawing. Size(418, 422);
this.ViewPort.T abIndex = 8;
this.ViewPort.T abStop = false;
//
// DataPane
//
this.DataPane.L ocation = new System.Drawing. Point(4, 4);
this.DataPane.N ame = "DataPane";
this.DataPane.S ize = new System.Drawing. Size(52, 56);
this.DataPane.T abIndex = 9;
this.DataPane.T abStop = false;
//
// ScrollPane
//
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.DataPane,
this.ViewPort,
this.btnReset,
this.vScroller,
this.hScroller,
this.pbContaine r});
this.Name = "ScrollPane ";
this.Size = new System.Drawing. Size(450, 450);
this.Resize += new System.EventHan dler(this.Scrol lPane_Resize);
this.ResumeLayo ut(false);
}
#endregion
private void ScrollPane_Resi ze(object sender, System.EventArg s e) {
DataPane.Parent = ViewPort;
pbContainer.Loc ation = new Point( 0, 0 );
pbContainer.Siz e = new Size( this.Width, this.Height );
hScroller.Locat ion = new Point( EDGE_PADDING, pbContainer.Hei ght -
(EDGE_PADDING + SCROLL_THICKNES S) );
hScroller.Size = new Size( pbContainer.Wid th - ( (EDGE_PADDING*2 ) +
SCROLL_THICKNES S), SCROLL_THICKNES S );
vScroller.Locat ion = new Point( pbContainer.Wid th - (EDGE_PADDING +
SCROLL_THICKNES S), EDGE_PADDING );
vScroller.Size = new Size( SCROLL_THICKNES S, pbContainer.Hei ght - (
(EDGE_PADDING*2 ) + SCROLL_THICKNES S ) );
btnReset.Size = new Size( SCROLL_THICKNES S, SCROLL_THICKNES S );
btnReset.Locati on = new Point( pbContainer.Wid th - (EDGE_PADDING +
SCROLL_THICKNES S), pbContainer.Hei ght - (EDGE_PADDING +
SCROLL_THICKNES S) );
ViewPort.Parent = pbContainer;
ViewPort.Locati on = new Point( 0, 0 );
ViewPort.Size = new Size( pbContainer.Wid th - ((EDGE_PADDING* 2) +
SCROLL_THICKNES S), pbContainer.Hei ght - ((EDGE_PADDING* 2) +
SCROLL_THICKNES S ) );
CalculateScroll bars();
}
private void CalculateScroll bars(){
hScroller.Enabl ed = ( DataPane.Width > ViewPort.Width );
if( hScroller.Enabl ed ){
hScroller.Maxim um = (DataPane.Width - ViewPort.Width) +120;
hScroller.Minim um = 0;
}
vScroller.Enabl ed = ( DataPane.Height > ViewPort.Height );
if( vScroller.Enabl ed ){
vScroller.Maxim um = (DataPane.Heigh t - ViewPort.Height )+120;
vScroller.Minim um = 0;
}
}
private void SetButtonBehavi or( ResetButtonBeha viors behavior ){
switch( behavior ){
case ResetButtonBeha viors.Normal:
btnReset.Enable d = true;
btnReset.Visibl e = true;
break;
case ResetButtonBeha viors.Hidden:
btnReset.Visibl e = false;
btnReset.Enable d = true;
break;
case ResetButtonBeha viors.Disabled:
btnReset.Visibl e = true;
btnReset.Enable d = false;
break;
}
}
private void btnReset_Click( object sender, System.EventArg s e) {
if( ResetClicked != null ){
ResetClicked( btnReset, e );
}
}
private void vScroller_Scrol l(object sender,
System.Windows. Forms.ScrollEve ntArgs e) {
int val = vScroller.Value ;
DataPane.Top = (-1 * val)+1;
}
private void hScroller_Scrol l(object sender,
System.Windows. Forms.ScrollEve ntArgs e) {
int val = hScroller.Value ;
DataPane.Left = (-1 * val)+1;
}
public ResetButtonBeha viors ResetButtonBeha vior{
get{
return pResetButtonBeh avior;
}
set{
pResetButtonBeh avior = value;
SetButtonBehavi or( pResetButtonBeh avior );
}
}
public PictureBox DataPanel {
get{
return this.DataPane;
}
}
public Size DataPaneSize {
get{
return DataPane.Size;
}
set{
DataPane.Size = value;
CalculateScroll bars();
}
}
}
}
//</CODE>
"Kristof Nachtergaele" <ik**@nie.com > wrote in message news:<3f******* *************** *@reader1.news. skynet.be>...
Hi,
I'm looking for something, which acts as a container, that I can drop onto
my form and which has a size that is bigger than the visible part, the
invisible pazrt being scrollable to with scrollbars. Actually it boils down
to a form in a form in a certain way, does anyone have any idea if there is
allready such a component around somewhere, and if not from which class to
start to create it?
thx,
Kristof