using System;
using System.Windows.Forms;
public class formlayout : Form
{
private ListBox mLB1 = new ListBox();
private ListBox mLB2 = new ListBox();
private ListBox mLB3 = new ListBox();
private void InitializeComponent()
{
//...
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.HandleLayout);
//...
}
//----------------------------------------
//There are 3 list boxes side by side
//make the height of all 3 the same as the main window's client
//make the first a fixed width
//make the second and third take up the remaining width
private void HandleLayout(object sender, LayoutEventArgs e)
{
int gap = 5;
//set the height to the main window's height
mLB1.SetBounds(0,0,0,this.ClientSize.Height,BoundsSpecified.Y | BoundsSpecified.Height);
//get the right edge of the first list box
int rightedge = mLB1.Bounds.X + mLB1.Bounds.Width;
//calculate the remainder of the space in the client window
int lbwidth = (this.ClientSize.Width - rightedge - gap) / 2;
//the left edge of the next list box is the last list box's right edge
//plus a gap
int leftedge = rightedge + gap;
mLB2.SetBounds(leftedge,0,lbwidth,this.ClientSize.Height);
leftedge += lbwidth;
mLB3.SetBounds(leftedge,0,lbwidth,this.ClientSize.Height);
Invalidate();
}
}
|