Welcome to the new platform of Programmers 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 it's 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?
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
Public Sub ChangeTabPanelColor()
'change the color of the panel in the first tab
'TabControl1.TabPages(0).panel.BackColor = Color.HotPink
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Any help would be appreciated.