Add Button to Tab Page (using code)

S

Steve

I'm using "Dim btn As New ButtonArray(Me)" to create a series of
buttons on my form. However, I'd prefer it if they were created on a
tab page of a tab control. Is this possible?

My code:
Dim X As Integer = 10
Dim Y As Integer = 10

Dim bttnCount As Integer = 1

TabPage2.Focus()

Dim btn As New ButtonArray(Me)
Dim iTest As Integer
For iTest = 0 To objDataView.Count - 1
btn.Add(objDataView(iTest)("ExtraType"))
btn(iTest).Size = New System.Drawing.Size(96, 56)
btn(iTest).BackColor = Color.White
btn(iTest).Name = "Button" & iTest
btn(iTest).Location = New Point(X, Y)
AddHandler btn(iTest).Click, AddressOf btn_Click

bttnCount = bttnCount + 1

X = X + 96

If bttnCount > 8 Then
Y = Y + 56
X = 10
bttnCount = 1
End If
Next
 
K

Ken Tucker [MVP]

Hi,

Try adding the button to the tabpage.

TabPage2.Controls.Add(btn(iTest))

AddHandler btn(iTest).Click, AddressOf btn_Click

bttnCount = bttnCount + 1


Ken
-------------------------
I'm using "Dim btn As New ButtonArray(Me)" to create a series of
buttons on my form. However, I'd prefer it if they were created on a
tab page of a tab control. Is this possible?

My code:
Dim X As Integer = 10
Dim Y As Integer = 10

Dim bttnCount As Integer = 1

TabPage2.Focus()

Dim btn As New ButtonArray(Me)
Dim iTest As Integer
For iTest = 0 To objDataView.Count - 1
btn.Add(objDataView(iTest)("ExtraType"))
btn(iTest).Size = New System.Drawing.Size(96, 56)
btn(iTest).BackColor = Color.White
btn(iTest).Name = "Button" & iTest
btn(iTest).Location = New Point(X, Y)
AddHandler btn(iTest).Click, AddressOf btn_Click

bttnCount = bttnCount + 1

X = X + 96

If bttnCount > 8 Then
Y = Y + 56
X = 10
bttnCount = 1
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top