spacer
Yehuda Shiran September 4, 2002
Creating Docking Windows
Tips: September 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Many applications build their user interfaces with dockable windows. The advantage of dockable windows is that you can control the size of each window, while the container window prevents them from cluttering each other. You can achieve the effect of docking using either the Dock or Anchor property of the Panel class.

Let's look at an example where we use a Windows form to create three dockable panels on the bottom, top, and left sides of the container panel. Here is the definition of the container panel:

  basePanel= new Panel;
  basePanel.Location= new Point(0,0);
  basePanel.Size= new System.Drawing.Size(500,300);
  basePanel.Name= "basePanel";
  basePanel.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
Here is the definition of the left panel. It is docked with the Dock property, and it also has a 3D-style border:

  leftPanel= new Panel;
  leftPanel.Location= new Point(0,0);
  leftPanel.Size= new System.Drawing.Size(100,300);
  leftPanel.Name= "leftPanel";
  leftPanel.Dock= DockStyle.Left;
  leftPanel.BorderStyle = "Fixed3D";
We define the top panel in a similar way, using the Anchor property for docking:

  topPanel= new Panel;
  topPanel.Location= new Point(100,0);
  topPanel.Size= new System.Drawing.Size(400,200);
  topPanel.Name= "topPanel";
  topPanel.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
  topPanel.BorderStyle = "Fixed3D";
We define the third panel as follows:

  bottomPanel= new Panel;
  bottomPanel.Location= new Point(100,200);
  bottomPanel.Size= new System.Drawing.Size(400,100);
  bottomPanel.Name= "bottomPanel";
  bottomPanel.Anchor= AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
  bottomPanel.BorderStyle = "Fixed3D";
We need to add the three panels to the base panel:

  basePanel.Controls.Add(topPanel);
  basePanel.Controls.Add(bottomPanel);
  basePanel.Controls.Add(leftPanel);
To learn more about JScript .NET and ASP.NET, go to Column 117, JScript .NET, Part XI: Creating Windows Forms.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint