Question click buttons

andrews

Well-known member
Joined
Nov 22, 2011
Messages
167
Programming Experience
5-10
I have a matrix of buttons and I want by clicking any button to set a text (1 letter) in the button
like something : (matrixbut(i,j).text = inputbox(...
The sub :
 Public Sub makebuttongrid()
        Dim i, j  As Integer
        myFont = New System.Drawing.Font("Arial", 11, FontStyle.Bold) 
        For i = 1 To 15
            For j = 1 To 15
                matrixbut(i, j) = New Button
                matrixbut(i, j).Left = start + i * 25
                matrixbut(i, j).Top = start + j * 25
                matrixbut(i, j).Width = 30
                matrixbut(i, j).Height = 30
                matrixbut(i, j).Visible = True
                matrixbut(i, j).Font = myfont
                Me.Controls.Add(matrixbut(i, j))
            Next
        Next
end sub

Thanks for any response
 
Last edited by a moderator:
I'm not sure that I completely understand the problem. The first thing that I would ask is why you're creating the Buttons in code rather than in the designer. You know exactly what you want at design time so why use code? You'd normally only use code if there was some aspect at least that you didn't know until run time.
 
I'm not sure that I completely understand the problem. The first thing that I would ask is why you're creating the Buttons in code rather than in the designer. You know exactly what you want at design time so why use code? You'd normally only use code if there was some aspect at least that you didn't know until run time.

I it easy to do that creating 225 buttons in designode?
I did not knew.
 
There are many buttons (15*15 = 225) and by making them in code it is also easier to place the buttons correctly.

No it isn't. That's exactly what the TableLayoutPanel control is for.
 

Latest posts

Back
Top