You could also simplify your code to look similar to this:
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim xPos, yPos As Integer
Dim p As Integer = -1
For i As Integer = 1 To 10
' Let panel hold the Buttons - Toggle example
pnlButtons.Controls.Add(New AdvancedHMIControls.BasicButton With {
.ComComponent = Me.ModbusTCPCom1,
.PLCAddressClick = "0000" & i,
.Text = i,
.UseVisualStyleBackColor = True,
.OutputType = 4,
.Width = 100,
.Height = 100,
.Left = xPos,
.Top = yPos})
xPos += 100
p += 1
If (p = 4) Then ' Location of second line of buttons:
xPos = 0
yPos += 100
p = -1
End If
Next
End Sub
The attached 1st picture shows what it looks like with a MODRSsim2 simulator next to it (for this example).
Unless you really need array and "s" variable, just make changes as you need it to be.
The attached 2nd picture shows what it looks like with Highlight enabled (and also with a MODRSsim2 simulator next to it), the code is slightly changed:
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim xPos, yPos As Integer
Dim p As Integer = -1
For i As Integer = 1 To 10
' Let panel hold the Buttons - Toggle example with Highlight
pnlButtons.Controls.Add(New AdvancedHMIControls.BasicButton With {
.ComComponent = Me.ModbusTCPCom1,
.PLCAddressClick = "0000" & i,
.PLCAddressHighlightX = "0000" & i,
.Text = i,
.OutputType = 4,
.Width = 100,
.Height = 100,
.Left = xPos,
.Top = yPos})
xPos += 100
p += 1
If (p = 4) Then ' Location of second line of buttons:
xPos = 0
yPos += 100
p = -1
End If
Next
End Sub