コントロールの前後関係は、Controlsコレクションに追加された順番に依存します。
BringToFrontメソッドやSendToBackメソッドを利用して、その順番を動的に変更することが可能です。
-------------------------------------------------------
using System;
using System.Windows.Forms;
class WinSample : Form
{
private Button mybutton1;
private Button mybutton2;
public static void Main()
{
Application.Run(new WinSample());
}
public WinSample()
{
this.SuspendLayout();
this.Text = "前後入れ替え";
this.mybutton1 = new Button();
this.mybutton1.Location = new System.Drawing.Point(30, 30);
this.mybutton1.Size = new System.Drawing.Size(120, 120);
this.mybutton1.Text = "ボタン1";
this.mybutton1.Click += new EventHandler(this.mb_Click);
this.mybutton2 = new Button();
this.mybutton2.Location = new System.Drawing.Point(130, 100);
this.mybutton2.Size = new System.Drawing.Size(120, 120);
this.mybutton2.Text = "ボタン2";
this.mybutton2.Click += new EventHandler(this.mb_Click);
this.Controls.Add(mybutton1);
this.Controls.Add(mybutton2);
this.ResumeLayout(false);
}
private void mb_Click(object sender, EventArgs e)
{
((Button)sender).BringToFront();
this.Controls[0].Text = "前";
this.Controls[1].Text = "後";
}
}
-------------------------------------------------------
あおい情報システム株式会社 小野修司(どっとねっとふぁん)