How does Something.Controls.Add work? How to reference it? - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

daveatondaveaton Posts: 1Member
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.

[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.TabPages.Add(myTabPage)
TabControl1.SelectedTab = myTabPage

myPanel.Dock = DockStyle.Fill
myPanel.Visible = True
myPanel.BackColor = Color.Green
myPanel.Name = "testPanel"
myTabPage.Controls.Add(myPanel)

'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
ChangeTabPanelColor()
End Sub

End Class
[/code]


Any help would be appreciated.




Sign In or Register to comment.