d0minik
New member
Hi everyone,
first of all - I hope i posted in the right Forum. My Problem is, that I have some Buttons, Labels and TextBoxes I need to generate after the User told a number of Players. With the Code I'm using now only the last Player will have these Controls working, because they are moved - for example - from Player 1 to Player 3.
I was looking for several hours in the Internet with Google and so on and found out, that a "ControlArray" should help out, BUT I did not find any help on how to create such a ControlArray. The biggest Problem I have is, that these buttons have to have names like "1", "2", "3" and so on (or if it works somehow to read out the Index of a ControlArray the names will not be necessary).
This is the code I am using right now to generate the Controls, but as you see it won't work, because the properties will be changed when the For-Function restarts.What I need is a hint on how to get these Controls/Buttons into a Control-Array and then read out the Index-Number to use them in the Functions that are called. Hopefully you know, what I mean.
Thanks everybody for reading and help! :encouragement:
EDIT: Got it allready! It's very easy, if you know how to do it :
This worked with some changes for me!
first of all - I hope i posted in the right Forum. My Problem is, that I have some Buttons, Labels and TextBoxes I need to generate after the User told a number of Players. With the Code I'm using now only the last Player will have these Controls working, because they are moved - for example - from Player 1 to Player 3.
I was looking for several hours in the Internet with Google and so on and found out, that a "ControlArray" should help out, BUT I did not find any help on how to create such a ControlArray. The biggest Problem I have is, that these buttons have to have names like "1", "2", "3" and so on (or if it works somehow to read out the Index of a ControlArray the names will not be necessary).
This is the code I am using right now to generate the Controls, but as you see it won't work, because the properties will be changed when the For-Function restarts.What I need is a hint on how to get these Controls/Buttons into a Control-Array and then read out the Index-Number to use them in the Functions that are called. Hopefully you know, what I mean.
Thanks everybody for reading and help! :encouragement:
EDIT: Got it allready! It's very easy, if you know how to do it :
VB.NET:
Public Class Form1
Private btnTestNumButtons() As System.Windows.Forms.Button
Private Sub CreateButtonArray()
Dim shtIndex As Short
ReDim btnTestNumButtons(10)
For shtIndex = 0 To 9
btnTestNumButtons(shtIndex) = New System.Windows.Forms.Button
With btnTestNumButtons(shtIndex)
.Text() = shtIndex.ToString() 'Set text caption
.Size() = New Size(40, 40) 'Set the button size
.FlatStyle() = FlatStyle.Popup 'Set the button flat style
.BackColor() = System.Drawing.Color.Blue 'Set the background color
AddHandler .Click, AddressOf Me.btnTestNumButtons_Click 'Attach handler reference
End With
Next
Me.Controls.AddRange(btnTestNumButtons)
ButtonStackOrder()
End Sub
This worked with some changes for me!
Last edited: