我用循环手动生成按钮(可以自定义横列的个数自动生成)并且放到泛型集合里list<button>里
我想对list里所有的按钮进行操作 (这些操作都要在属性中实现和操作)
例如:我想改变每个按钮上文字的位置 。
谁有好的方法
最好能给段代码
我想好久都没想出来

解决方案 »

  1.   

    用TABLELAYOUTPANEL就能很好地进行排版
      

  2.   

    用TABLELAYOUTPANEL就能很好地进行排版
      

  3.   

    为了改变按钮状态 必须对list里的按钮进行操作(在属性中)
    就是要找到list里所有的按钮  怎么能实现
      

  4.   

    给list里面的按钮注册事件不就可以了吗?事件应该都是一样的吧,通过事件的参数Button btn = sender as Button;来得到你需要的button
      

  5.   

    可以用for循环添加
    设置按钮的X,Y坐标和设置按钮上面的字
    然后添加到窗体里面
      

  6.   

    如果想设置集合中的BUTTON属性
    对于公共的属性,可以用FOR 或者FOREACH做个循环操作,对每个BUTTON属性进行设置
    如果需要对某个特别的BUTTON设置其属性,就在循环里面做个IF判断,或者直接制定到某个BUTTON(LIST(INDEX)用IF判断,不用循环
      

  7.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace buttoncontrol
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {            Button b = new System.Windows.Forms.Button();
                // 
                // button1
                // 
                b.Location = new System.Drawing.Point(61, 105);
                b.Name = "button1";
                b.Size = new System.Drawing.Size(75, 23);
                b.TabIndex = 0;
                b.Text = "button1";
                b.UseVisualStyleBackColor = true;
                this.Controls.Add(b);                      Button c = new System.Windows.Forms.Button();
                // 
                // button1
                // 
                c.Location = new System.Drawing.Point(200, 105);
                c.Name = "button2";
                c.Size = new System.Drawing.Size(75, 23);
                c.TabIndex = 0;
                c.Text = "button2";
                c.UseVisualStyleBackColor = true;
                this.Controls.Add(c);
                Button q =(Button)this.Controls["button1"];
                q.Click += new EventHandler(q_Click);
            }        void q_Click(object sender, EventArgs e)
            {
                ((Button)sender).Text = "second";
            }
        }
    }
      

  8.   

    Button btn = new Button();
    btn.Left = 0;
    btn.Top = 0;
    btn.Width = 0;
    btn.Height = 0;
    btn.Text = "";
    btn.TextAlign = ContentAlignment.MiddleCenter;
    this.Controls.Add(btn);
      

  9.   

    谢谢各位
    但是我是要对生成后的按钮进行修改我试过用for 和foreach  但是在属性get{}中不能用 如果谁能这样实现最好些个例子试试
    用事件我还真没试过,不过在属性中 Button btn = sender as Button 能用??
      

  10.   

    public Form1()
            {
                InitializeComponent();
                List<Button> buttonList = new List<Button>();            // construct buttons
                for (int i = 0; i < 10; i++)
                {
                    Button b = new Button();
                    b.Text = i.ToString();
                    this.flowLayoutPanel1.Controls.Add(b);
                    buttonList.Add(b);
                }            // modify buttons properties
                foreach (Button b in buttonList)
                {
                    b.TextAlign = ContentAlignment.MiddleLeft;
                }
            }不知道LZ是不是想要这样的效果
      

  11.   

    但是在属性get{}中不能用 是什么意思?和你这问题是两码事吧,你最好说清楚你的意思,要么把你错误的代码贴出来