楼上说的正确,微软的这个控件的确麻烦,那就是说每个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); }
this.tabControl1.SelectedTab.ForeColor=Color.Purple;//文字的颜色
this.tabControl1.SelectedTab.Text="dfasf";//文本内容更改
{
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);
}
}
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);
}
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;