VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How does Something.Controls.Add work? How to reference it? Posted by daveaton on 3 Oct 2011 at 3:43 PM
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.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



Any help would be appreciated.







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.