2009年12月13日 星期日

C# create a 2 dimention List :: button

        public List<List<System.Windows.Forms.Button>> aa;
        private List<System.Windows.Forms.Button> a;


             aa = new List<List<System.Windows.Forms.Button>>();


            for (int j = 0; j < 4; j++)
            {
                a = new List<System.Windows.Forms.Button>();

               
                for (int i = 0; i < 4; i++)
                {
                    a.Add(new System.Windows.Forms.Button());

                    this.a[i].Location = new System.Drawing.Point(i * 30, j * 30);
                    this.a[i].Name = "asd";
                    this.a[i].Size = new System.Drawing.Size(54, 38);
                    this.a[i].TabIndex = 0;
                    this.a[i].Text = "but[i]";
                    this.a[i].UseVisualStyleBackColor = true;
                }

                aa.Add(a);
            }



            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    this.Controls.Add(this.aa[i][j]);
                }
            }

沒有留言:

張貼留言