在VS2008中,创建tabcontrol的话
会预提供2个tabpage然后我们如果需要新增新的tabpage的话
            TabPage tabpage = new TabPage();
            tabpage.ImageIndex = 0;
            tabpage.Text = textBox1.Text;
            tabControl1.TabPages.Add(tabpage);
按照这样的方式就可以新增了小弟的问题是
在“设计”窗口里,我们可以往tabpage里面拖入各种其他的控件,从而实现每个分页内的控件显示
我这样写了
            Button tabbutton = new Button();
            tabbutton.Name=tabbutton.Text = "newbutton";
            tabbutton.Location = new System.Drawing.Point(6, 23);
            tabbutton.Size = new System.Drawing.Size(35, 12);            tabbutton.TabIndex = tabControl1.TabPages.IndexOf(tabpage);
但是在我添加的分页中没有显示出我手动创建的button啊,哪里出问题了?

解决方案 »

  1.   

     this. tabControl1.Controls.Add(tabbutton);
      

  2.   

    需要添加到控件中,
     tabbutton.TabIndex = tabControl1.TabPages.IndexOf(tabpage); 
    改成
    this. tabControl1.Controls.Add(tabbutton);
    就行了。
      

  3.   


    跳警告啦,说只有tabpage才能add到tabcontrol中去
      

  4.   

    先把Button添加到TabPage里面,然后在把TabPage添加到TabControl里面。
      

  5.   

    tabbutton.TabIndex = tabControl1.TabPages.IndexOf(tabpage); 
    关于这句自己理解错误
    是Tab键的顺序,不是tabpage的索引