2012-05-07 20 views
0

C#WinFormプロジェクトに問題があります。ボタンの配置方法は?

私のプロジェクトでは四角形を描画する機能があり、実行時にボタンを作成する機能があります。私がしたいことは、ボタンが正方形に置かれることです。

2つの配列を使用しようとしています。 1つは正方形のx位置を取得し、もう1つはy位置を取得します。

ボタンはxとyの位置に1列ずつ配置されていますが、斜めに配置されています。

int[] locationx = new int[100]; 
    int[] locationy = new int[100]; 
    int monex = 0; 
    int money = 0; 
    private void DrawAllSquares()//z,k its many square its going to draw 
    { 
     int tempy = y; 
     for (int i = 0; i < z; i++) 
     { 
      DrawingSquares(x, y); 
      for (int j = 0; j < k - 1; j++) 
      { 
       locationy[money] = tempy; 
       money++; 
       tempy += 60; 
       DrawingSquares(x, tempy); 
      } 
      x += 120; 
      locationx[monex] = x; 
      monex++; 
      tempy = y; 
     } 

    } 
     private void button2_Click(object sender, EventArgs e) 
    { 
          Button myText = new Button(); 
      myText.Tag = counter; 
      //changeplace(); 
      myText.Location = new Point(locationx[monex2], locationy[money2]); 
      monex2++; 
      money2++; 
      buttonList.AddLast(myText); 
      myText.Text = Convert.ToString(textBox3.Text); 
      this.Controls.Add(myText); 
      buttons[counter] = myText; 
      myText.BringToFront(); 
      counter++; 
    } 

答えて

1

あなたはフォーム Controlsコレクションに作成したボタンを追加する必要があります。

private void button2_Click(object sender, EventArgs e) 
{ 
    Button myText = new Button(); 
    myText.Tag = counter; 
    myText.Location = new Point(locationx[monex2], locationy[money2]); 
    Controls.Add(myText); // Assuming that handler 'button2_Click' is in your Form class. 
    // rest of your code 
} 

EDIT

Button myText = new Button(); 
myText.Click += button2_Click; 
+0

は私がその機能 –

+0

はいを​​持っていますが、私はこの行を意味する:** Controls.Add(MYTEXTを); **私の編集:) [OK]を –

+0

ロック、だからどこのエラー/問題? –

関連する問題