C# 我有代码,创建20个按钮水平,如何使按钮垂直
这是创建按钮的代码C# 我有代码,创建20个按钮水平,如何使按钮垂直,c#,C#,这是创建按钮的代码 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;
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;
}
public System.Windows.Forms.Button creatbtn()
{
对于(int i=0;i<20;i++)
{
btn=新的System.Windows.Forms.Button();
this.Controls.Add(btn);
btn.Top=c*28;
btn.左=150;
btn.Text=“button”+这个.c.ToString();
c=c+1;
}
返回btn;
}
像@Dmitry Bychenko sait
就像你在上面做的一样,但在左边做
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;
}
public System.Windows.Forms.Button creatbtn()
{
对于(int i=0;i<20;i++)
{
btn=新的System.Windows.Forms.Button();
this.Controls.Add(btn);
//btn.Top=c*28
btn.Top=28;
//btn.左=150
btn.左=150+(c*(btn.宽度+5));
btn.Text=“button”+这个.c.ToString();
C++;
}
返回btn;
}
动态计算左侧
而不是顶部
以水平对齐按钮-当前按钮垂直对齐btn.Top=28;btn.左=150+c*80代码>