我有代码,水平创建20个按钮,如何垂直按钮

时间:2017-03-20 19:11:26

标签: c#

enter image description here

这是创建按钮的代码

      public System.Windows.Forms.Button creatbtn()
    {
        for (int i = 0; i < 20; i++)
        {
        btn = new System.Windows.Forms.Button();
        this.Controls.Add(btn);
        btn.Top = c * 28;
        btn.Left = 150;
        btn.Text = "button" + this.c.ToString();
        c = c + 1;


        }
        return btn;
    }

1 个答案:

答案 0 :(得分:0)

喜欢@Dmitry Bychenko sait 就像你为top做的一样,但是做左手

public System.Windows.Forms.Button creatbtn()
{
    for (int i = 0; i < 20; i++)
    {
        btn = new System.Windows.Forms.Button();
        this.Controls.Add(btn);

        //btn.Top = c * 28
        btn.Top = 28;

        //btn.Left = 150
        btn.Left = 150 + (c * (btn.Width + 5));

        btn.Text = "button" + this.c.ToString();
        c++;
    }
    return btn;
}