Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How does Something.Controls.Add work? How to reference it?

daveatondaveaton Member Posts: 1
Ok what I am doing is from a blank from add a Tab Control with No Tabs. Then add 2 buttons to the form.

I add a tab via code and then add a panel inside the tab and change the color to green.

Now in another sub I want to change the Panel color to pink but I am not sure how to access it without changing the scope.

here is the code.

Public Class Form1

Dim TabInstance As Integer = 0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTabPage As New TabPage()
Dim myPanel As New Panel()

myTabPage.Name = TabInstance
myTabPage.Text = CStr(TabInstance)

TabControl1.SelectedTab = myTabPage

myPanel.Dock = DockStyle.Fill
myPanel.Visible = True
myPanel.BackColor = Color.Green
myPanel.Name = "testPanel"

'set counter for next time
TabInstance = TabInstance + 1

End Sub

Public Sub ChangeTabPanelColor()
'change the color of the panel in the first tab
'TabControl1.TabPages(0).panel.BackColor = Color.HotPink
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub

End Class

Any help would be appreciated.

Sign In or Register to comment.