using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;namespace SwingSet2
{
public class SplitPanelDemo : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox1; private System.ComponentModel.Container components = null;
        private static String paths = SwingSet.path+"resources\\images\\splitpane\\";
public SplitPanelDemo()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Component Designer generated code
private void InitializeComponent()
{
this.panel2 = new System.Windows.Forms.Panel();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel2.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
this.panel2.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox3,this.textBox2,this.textBox1,
this.radioButton2,this.radioButton1,this.label1,this.label2,this.label3});
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 408);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(808, 112);
this.panel2.TabIndex = 2;
this.textBox3.Location = new System.Drawing.Point(160, 80);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(56, 20);
this.textBox3.TabIndex = 8;
this.textBox3.Text = "20";
this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox3_KeyPress);
this.textBox2.Location = new System.Drawing.Point(160, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(56, 20);
this.textBox2.TabIndex = 7;
this.textBox2.Text = "20";
this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
this.textBox1.Location = new System.Drawing.Point(160, 32);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(56, 20);
this.textBox1.TabIndex = 6;
this.textBox1.Text = "5";
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
this.radioButton2.Checked = true;
this.radioButton2.Location = new System.Drawing.Point(128, 8);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(112, 16);
this.radioButton2.TabIndex = 1;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "&Horizontal Split";
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
this.radioButton1.Cursor = System.Windows.Forms.Cursors.Default;
this.radioButton1.Location = new System.Drawing.Point(16, 8);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(96, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.Text = "&Vertical Split";
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.TabIndex = 3;
this.label1.Text = "&Splitter Width:";
this.label2.Location = new System.Drawing.Point(8, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(136, 23);
this.label2.TabIndex = 4;
this.label2.Text = "&Splitter MinSize:";
this.label3.Location = new System.Drawing.Point(8, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(136, 16);
this.label3.TabIndex = 5;
this.label3.Text = "&Splitter MinExtra:";
this.splitter1.BackColor = System.Drawing.Color.LightGray;
this.splitter1.Location = new System.Drawing.Point(240, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(8, 400);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
this.panel1.Anchor =(((System.Windows.Forms.AnchorStyles.Top 
| System.Windows.Forms.AnchorStyles.Bottom) 
| System.Windows.Forms.AnchorStyles.Left) 
| System.Windows.Forms.AnchorStyles.Right);
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {this.pictureBox2,this.splitter1,this.pictureBox1});
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(808, 400);
this.panel1.TabIndex = 3;
this.pictureBox2.BackColor = System.Drawing.Color.Black;
this.pictureBox2.Image = Image.FromFile(paths+"moon.jpg");
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox2.Location = new System.Drawing.Point(248, 0);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(560, 400);
this.pictureBox2.TabIndex = 2;
this.pictureBox2.TabStop = false;
this.pictureBox1.BackColor = System.Drawing.Color.Black;
this.pictureBox1.Image = Image.FromFile(paths+"earth.jpg");
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Left;
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(240, 400);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.Controls.AddRange(new System.Windows.Forms.Control[] {   this.panel1,   this.panel2});
this.Name = "SplitPanelDemo";
this.Size = new System.Drawing.Size(808, 520);
this.Load += new System.EventHandler(this.SplitPanelDemo_Load);
this.SizeChanged += new System.EventHandler(this.SplitPanelDemo_SizeChanged);
this.panel2.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion

解决方案 »

  1.   


    private void SplitPanelDemo_Load(object sender, System.EventArgs e)
    {
    this.panel2.Location=new Point(100,100);
    } private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
    {
    this.pictureBox1.Height=this.splitter1.Location.X;
    this.pictureBox1.Dock = DockStyle.Top;
    this.splitter1.Dock = DockStyle.Top;
    this.panel2.Location=new Point(100,100); } private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
    {
    this.pictureBox1.Dock = DockStyle.Left;
    this.splitter1.Dock = DockStyle.Left;
    } private void SplitPanelDemo_SizeChanged(object sender, System.EventArgs e)
    {
    this.panel2.Location=new Point(100,100);
    }
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar==(char)13)
    try
    {
    if ((Convert.ToInt32(textBox1.Text))<=0)
    {
    MessageBox.Show("Invalid Splitter Width&pound;&iexcl;","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    else
    {
    this.splitter1.Width=(Convert.ToInt32((textBox1.Text).Trim()));
    }
    }
    catch(Exception)
    {
    MessageBox.Show("Invalid Splitter Width&pound;&iexcl;","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    }
    private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar==(char)13)
    {
    try
    {
    if (Convert.ToInt32(textBox2.Text.Trim())<=10)
    {
    MessageBox.Show("Invalid Splieter minimum Size and bigger than 10 &pound;&iexcl;","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    else
    {
    this.splitter1.MinSize=(Convert.ToInt32(textBox2.Text.Trim()));
    }
    }
    catch(Exception)
    {
    MessageBox.Show("Invalid Splieter minimum Size and bigger than 10 &pound;&iexcl;","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    }
    }
    private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar==(char)13)
    {
    try
    {

    if ((Convert.ToInt32(textBox3.Text.Trim()))<=10)
    {
    MessageBox.Show("Invalid  Spliter minimum Extra size and must bigger than  10&pound;&iexcl;","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    else
    {
    this.splitter1.MinExtra=Convert.ToInt32(textBox3.Text.Trim());
    }
    }
    catch(Exception)
    {

        MessageBox.Show("Invalid  Spliter minimum Extra size and must bigger than  10&pound;&iexcl;","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    }
    }
    }
    }