473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Panel with scrollbars

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
Nov 15 '05 #1
1 17502
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.vScro ller_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.hScro ller_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>

"Kristof Nachtergaele" <ik**@nie.com> wrote in message news:<3f***********************@reader1.news.skyne t.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

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Raymond Dynowski | last post by:
How do you force a panel to scroll in code. I have a large picture box inside my panel. I would like the panel to default to the centre of the screen, rather than the scrollbars showing the top...
2
by: Sascha Schmidt | last post by:
Hello ! I'm trying to combine an external (not part of the panel) vertical scrollbar (VScrollBar) with a panel in order to scroll the content of the panel vertically using the external ...
0
by: Tom | last post by:
I have a panel that is set for autoscrolling, however I -DON'T- want the scrollbars to show up. Do anyone know of any way to make a panel autoscroll and yet have no scrollbars? I know that is an...
5
by: Rob T | last post by:
To keep my example simple, let's say I have a windows application form with a panel in it. For this example, I want to draw a single line in the panel, which is larger than the size of the panel. ...
0
by: Dan Sikorsky | last post by:
I have labels and associated multiline textboxes on a panel that's disabled for the purpose of presenting lengthy readonly comments. Using this method, the textbox scrollbars don't work; the user...
0
by: Elroyskimms | last post by:
I have a fixed witdth panel control with horizontal scrollbars. In it, I load a table and in each table cell is an instance of a user control that I created it. In theory, 3-5 of these controls are...
1
by: mrabie | last post by:
Hi All, I know this has been discussed before but i can't really find an answer to what i want to do. I am developing an application for touchscreen using C#. It's going to be a fullscreen...
2
by: ATR2000 | last post by:
I have setup a Panel to have a width of 100% so that it will adjust to users screensize. Within the panel I have a table. Unfortunately the table holds a lot of data and exceeds the size of the...
5
by: kulabhishek | last post by:
Hi all, I am using panel with autoscroll = true in C# I have added dataGridView control inside panel. When the height and width of dataGridView increases and becomes more than panel size,...
2
by: kulabhishek | last post by:
Hello all. I have developed one user control "Grid" in C# and I am using it in another user control inside one panel. The AutoScroll property for the panel is enabled. When the height or...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.