Why is label not showing up in my tab?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Dransfield
    New Member
    • Jan 2011
    • 46

    #1

    Why is label not showing up in my tab?

    When I create the tab for the tab control and try to add the label to it, the label will not show. What am I doing wrong here?

    Code:
    private void FirstLogin()
            {
                TabPage loginTab = new TabPage("Login");
                loginTab.BackColor = SystemColors.Control;
    
                tabControl1.TabPages.Add(loginTab);
    
                Label loginLabel = new Label();
      
                loginLabel.Size = new System.Drawing.Size(25, 25);
                loginLabel.Location = new System.Drawing.Point(500,500);
                loginLabel.Text = "Test text!";
    
                this.Controls.Add(loginLabel);
            }
    Last edited by Niheel; Jan 25 '11, 01:48 PM. Reason: Question and explanation first, code last.
  • bentleyw
    New Member
    • Feb 2008
    • 32

    #2
    I believe you need to change:

    this.Controls.A dd(loginLabel);

    to

    loginTab.Contro ls.Add(loginLab el);

    Otherwise, you are adding the label to the main control (probably the form) instead of the tab page.

    Comment

    Working...