|
|
In this project, TestForm2.js, we introduce the concept of a multiple panels to create a layout. We use AnchorStyles and DockStyles to determine the behavior of the panels on resize. In this sample there are three panels, a docked left sided vertical panel containing a label, a bottom panel of buttons and a middle panel containing a textbox.
Source Codeimport System;
import System.Windows.Forms;
import System.ComponentModel;
import System.Drawing;
package JAL {
// demonstrates using multiple panels and docking to create a page layout
class TestForm extends System.Windows.Forms.Form {
// declare variables
private var label1: Label;
private var textBox1: TextBox;
private var button1, button2, button3: Button;
private var panelBase, panelBottom, panelMid, panelLeft: Panel;
// constructor
function TestForm() {
// label and size and position form
Text= "Resize Me!";
ClientSize= new System.Drawing.Size(500,300);
StartPosition= System.Windows.Forms.FormStartPosition.CenterScreen;
// create base panel
panelBase= new Panel;
panelBase.Location= new Point(0,0);
panelBase.Size= new System.Drawing.Size(500,300);
panelBase.Name= "panelBase";
// resize in all directions
panelBase.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
// create left docked panel
panelLeft= new Panel;
panelLeft.Location= new Point(0,0);
panelLeft.Size= new System.Drawing.Size(100,300);
panelLeft.Name= "panelLeft";
panelLeft.Dock= DockStyle.Left;
// create a label and add to left panel
label1= new Label;
label1.Location= new Point(0,0);
label1.Size= new System.Drawing.Size(80,20);
label1.Name= "label1";
label1.Text= "Label";
label1.Anchor= AnchorStyles.Left | AnchorStyles.Top;
panelLeft.Controls.Add(label1);
// create a mid panel
panelMid= new Panel;
panelMid.Location= new Point(100,0);
panelMid.Size= new System.Drawing.Size(400,200);
panelMid.Name= "panelMid";
// resize in all directions
panelMid.Anchor= AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
// create a TextBox and add to mid panel
textBox1 = new TextBox;
textBox1.Location= new Point(20,20);
textBox1.Size = new System.Drawing.Size(80,20);
textBox1.Name= "textBox1";
textBox1.Text = "Hello World";
textBox1.Anchor= AnchorStyles.Left | AnchorStyles.Top;
panelMid.Controls.Add(textBox1);
// create a bottom panel
panelBottom= new Panel;
panelBottom.Location= new Point(100,200);
panelBottom.Size= new System.Drawing.Size(400,100);
panelBottom.Name= "panelBottom";
// resize except in up direction
panelBottom.Anchor= AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
// create Buttons and add to bottom panel
button1= new Button;
button1.Location= new Point(20,60);
button1.Size= new System.Drawing.Size(80,20);
button1.Name= "button1";
button1.Text= "Button";
button1.Anchor= AnchorStyles.Left;
button2= new Button;
button2.Location= new Point(120,60);
button2.Size= new System.Drawing.Size(80,20);
button2.Name= "button2";
button2.Text= "Button";
button2.Anchor= AnchorStyles.Left;
button3= new Button;
button3.Location= new Point(220,60);
button3.Size= new System.Drawing.Size(80,20);
button3.Name= "button3";
button3.Text= "Button";
button3.Anchor= AnchorStyles.Left;
panelBottom.Controls.Add(button1);
panelBottom.Controls.Add(button2);
panelBottom.Controls.Add(button3);
// add mid, bottom and left panels to base panel
panelBase.Controls.Add(panelMid);
panelBase.Controls.Add(panelBottom);
panelBase.Controls.Add(panelLeft);
// add base panel to form
this.Controls.Add(panelBase);
} // end_constructor
} // end_class
}
// enable event loop
Application.Run(new JAL.TestForm());
Learn More About FormBuilderAlthough Visual Studio .NET does not support drag and drop creation of JScript Windows Form applications, TorrBoy has written a free JScript Windows Form code generator that takes XML as input. Here is a sample of the XML code used to generator a simple Form with a menu bar: You can download the FormBuilder at: http://www.gotdotnet.com/userfiles/torrboy/formbuilder.zip Previous Next |
Send mail to [email protected]
with questions or comments about this web site. Copyright © 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009 ©
|