どっとねっとふぁん

C# Tips And Samples
in 検索

22.コントロールの前後関係を変更する

最新の投稿は、投稿日時: 06-24-2005, 11:25 午前 投稿者: ono です。スレッドには 0 件の返答があります。
投稿のソート: 前へ 次へ
  •  06-24-2005, 11:25 午前 94

    22.コントロールの前後関係を変更する

    コントロールの前後関係は、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 = "後";
    
        }
    }
    
    -------------------------------------------------------


    あおい情報システム株式会社
     小野修司(どっとねっとふぁん)
RSS ニュースフィードで参照
SkinName:iroha_CS2
Powered by Community Server, by Telligent Systems