就是想在SelectedIndexChanged事件里,实现改变当前选中的tab页,tab页头的文字(标题)文字的颜色....

解决方案 »

  1.   

    this.tabControl1.SelectedIndex++;//改变选中页
    this.tabControl1.SelectedTab.ForeColor=Color.Purple;//文字的颜色
    this.tabControl1.SelectedTab.Text="dfasf";//文本内容更改
      

  2.   

    写了一段给你参考        this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;        private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
            {
                if (this.tabControl1.SelectedIndex == e.Index)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(216, 228, 248)), e.Bounds);
                    e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold), new SolidBrush(Color.Red), e.Bounds.Left + 4, e.Bounds.Top + 7, StringFormat.GenericDefault);
                }
                else
                {
                    e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, e.Font, new SolidBrush(Color.Black), e.Bounds.Left + 5, e.Bounds.Top + 8, StringFormat.GenericDefault);
                }
            }
      

  3.   

    楼上说的正确,微软的这个控件的确麻烦,那就是说每个tab页要想有这样的变化,都要重绘!
    public Form1()
        {
            TabControl tabControl1 = new TabControl();
            TabPage tabPage1 = new TabPage();        // Allows access to the DrawItem event. 
            tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;        tabControl1.SizeMode = TabSizeMode.Fixed;
            tabControl1.Controls.Add(tabPage1);
            tabControl1.ItemSize = new Size(80, 30);
            tabControl1.Location = new Point(25, 25);
            tabControl1.Size = new Size(250, 250);
            tabPage1.TabIndex = 0;
            ClientSize = new Size(300, 300);
            Controls.Add(tabControl1);        tabArea = tabControl1.GetTabRect(0);
            tabTextArea = (RectangleF)tabControl1.GetTabRect(0);        // Binds the event handler DrawOnTab to the DrawItem event 
            // through the DrawItemEventHandler delegate.
            tabControl1.DrawItem += new DrawItemEventHandler(DrawOnTab);
        }    // Declares the event handler DrawOnTab which is a method that
        // draws a string and Rectangle on the tabPage1 tab.
        private void DrawOnTab(object sender, DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen p = new Pen(Color.Blue);
            Font font = new Font("Arial", 10.0f);
            SolidBrush brush = new SolidBrush(Color.Red);        g.DrawRectangle(p, tabArea);
            g.DrawString("tabPage1", font, brush, tabTextArea);
        }
      

  4.   

    还有我已经定义了每个标签的内容,如果只是为了选中某个标签标题颜色有变化,都重绘是否很麻烦哦?tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;!!!!!(改成了程序来绘制的模式)
     private void MainFormtabControl_SelectedIndexChanged(object sender, EventArgs e)
            {
                TreeInfo ft = TreeInfo.GetForm();
                ft.DockableAreas = WeifenLuo.WinFormsUI.DockAreas.DockRight;
                ft.editBKMC.Text = this.MainFormtabControl.SelectedTab.Text;