2017-03-20 8 views
-4

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

ボタンを水平方向に並べるために 'Top'の代わりに' Left'を動的に計算します - 現在** **垂直に整列しています –

+0

'btn.Top = 28; btn.Left = 150 + c * 80; ' –

答えて

0

同様@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; 
}