如何用c#实现在vs2005环境,实现TabControl选中不同TabPage页时,tab页的文字变成红色?或者背景发生变化....
解决方案 »
- 求一个网站示例DEMO 要有服务端 以及客户端 整体代码
- 请问如何给读取一个csv文件内的图像信息(目录)并在pictureBox中显示?内详!
- 一条简单的sql语句
- 那位高手看看我这段反射有没有错啊
- 菜鸟有一个问题____使用C#编程中,我用"用户控件 "与GridView结合问题 "
- 当窗体装载的时候就用Label来显示登录用户的信息,可是..?
- 如何获取屏幕上坐标?
- ASP.NET[C#]连接sql server却始终出错! 死活找不出错在哪里! 请高手帮帮忙,谢谢.
- winform的问题
- 不知怎样才能让datagrid中得textbox得值不改变。
- 急,请大家帮忙(仅剩10分,大家别嫌少)。
- 数据库连接问题
http://www.codeproject.com/cs/miscctrl/flattabcontrol.asp
/// 画选项卡
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tcMain_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
if (tcMain.SelectedIndex == e.Index)
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(216,228,248)),e.Bounds);
e.Graphics.DrawString(tcMain.TabPages[e.Index].Text,new System.Drawing.Font("宋体",10,System.Drawing.FontStyle.Bold),new SolidBrush(Color.Black),e.Bounds.Left + 4,e.Bounds.Top + 7,StringFormat.GenericDefault);
}
else
{
e.Graphics.DrawString(tcMain.TabPages[e.Index].Text,e.Font,new SolidBrush(Color.Black),e.Bounds.Left + 5,e.Bounds.Top + 8,StringFormat.GenericDefault);
}
}
{this.MainFormtabControl.SelectedTab.ForeColor = Color.Red;
.........................
应用后,tab的标题,选中某个标签页没有变化,该怎么做?
可以按我的例子试一下,是用来改变Tab页标题的.需注意的是,还要修改Tab控件的一个属性的值,具体是什么名字我记不清了.
{
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);
}
}
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) {
if (this.tabControl1.SelectedIndex == e.Index) {
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0,0, 0)), e.Bounds);//标题头的背景颜色
e.Graphics.DrawString("好好",new Font("宋体",12),Brushes.Beige,new Point(12,12));
}
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;
这句要在事件里定义上,并在
private void MainFormtabControl_SelectedIndexChanged(object sender, EventArgs e)里面加上,效果实现了,只是在页面切换一瞬间,标签那块感觉被 一块颜色突然盖掉...
.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(212, 208, 200)), e.Bounds);
e.Graphics.DrawString(MainFormtabControl.TabPages[e.Index].Text, new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular), new SolidBrush(Color.Red), e.Bounds.Left + 4, e.Bounds.Top + 7, StringFormat.GenericDefault);