2016-04-01 13 views
-1

私は25ボタンをVB.Netのパネルの中に入れようとしています2015クラシックフォームPictureのように動作していません。あなたは助けてください可能性が...私のコード怒鳴るパネル内にボタンを配置する

Dim i As Integer 

    For i = 1 To 25 
     newButton = New Windows.Forms.Button 
     newButton.AutoSize = True 
     newButton.Name = "btnButton" & i 
     newButton.Text = "Button " & i 
     newButton.Top = i * 5 
     newButton.Left = i * 25 

     newButton.Size = New Size(95, 70) 

     AddHandler newButton.Click, AddressOf ButtonClicked 

     Panel1.Controls.Add(newButton) 

    Next 

enter image description here

+0

そして、「働いていないことは、」正確に何を意味?おそらく、斜めに重なっているボタンが表示されます。これはあなたが意味することですか? –

+0

はい、うまくいきます!しかし、彼らはあなたが望むように手配されていません。それを管理する方法についてもっと考えてみてください... – daro

答えて

1

あなたが何をする必要があるかあなたのコードは、ボタンを作成しており、問題は、彼らがそのように適切に配置されていないということである行でそれらをアレンジですと列。ここで私はあなたにこれをするのを手伝います。ここで

このスニペットは5列とn行でそれらを配置する方法を教えてくれます:

Dim x As Integer = 5 ' x co-ordinate of the point 
Dim y As Integer = 5 ' y co-ordinate of the point 
For i = 1 To 25 
    If i Mod 5 = 0 Then ' For starting next row after column 
     y += 100 ' 100 is not mandatory change as per size of button 
     x = 0 
    Else 
     x += 100 ' 100 is not mandatory change as per size of button 
    End If 
    Dim p As Point = New Point(x, y) 
    Dim newButton = New Windows.Forms.Button 
    newButton.Location = p 
    //do the rest of formatting here 
    Panel1.Controls.Add(newButton) 
Next 
関連する問題