September 4, 2002 - Creating Docking Windows | WebReference

September 4, 2002 - Creating Docking Windows

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

Yehuda Shiran, Ph.D.
Doc JavaScript

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:

To learn more about JScript .NET and ASP.NET, go to Column 117, JScript .NET, Part XI: Creating Windows Forms.