Visual Studio 2005中的选项卡控件背景色 [英] Tab control background color in visual Studio 2005

查看:121
本文介绍了Visual Studio 2005中的选项卡控件背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我知道如何根据我的应用程序需要更改Tab控件的背景颜色.此外,还应更改每个页面的选项卡的背景色.

问候,

Sushil Saini

解决方案

为了更改选项卡的背景颜色,将TabControl的DrawMode设置为OwnerDraw,然后处理DrawItem事件以进行绘制. "C#"> // 设置绘制模式并订阅DrawItem事件 .tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;




 私有 无效 tabControl1_DrawItem(对象发​​件人,System.Windows.Forms.DrawItemEventArgs e)
        {
            字体f;
            刷回来刷;
            刷前刷;

            如果(例如e.Index ==  this  .tabControl1.SelectedIndex)
            {
                f =  Font(例如,Font,FontStyle.Italic | FontStyle.Bold);
                backBrush =  System.Drawing.Drawing2D.LinearGradientBrush(例如,Bounds,Color.Blue,Color.Red,System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
                foreBrush = Brushes.PowderBlue;
            }
            其他
            {
                f = e.字体
                backBrush =  SolidBrush(e.BackColor);
                foreBrush =  SolidBrush(e.ForeColor);
            }

            字符串 tabName =  .tabControl1.TabPages [e.Index] .Text;
            StringFormat sf =  StringFormat();
            sf.Alignment = StringAlignment.Center;
            e.Graphics.FillRectangle(backBrush,e.Bounds);
            矩形r = e.Bounds;
            r =  Rectangle(rX,rY +  3 ,r.Width,r.Height- 3 );
            e.Graphics.DrawString(tabName,f,foreBrush,r,sf);

            sf.Dispose();
            如果(例如e.Index ==  this  .tabControl1.SelectedIndex)
            {
                f.Dispose();
                backBrush.Dispose();
            }
            其他
            {
                backBrush.Dispose();
                foreBrush.Dispose();
            }
        } 


^ ]帖子可能会有所帮助.


在表单加载事件中更改各个选项卡页面的背景颜色...

TabControl1.TabPages(0).BackColor = Color.White



希望这会给您一个想法.


Let me know how to change the Tab control''s background color as per my application need. Also background color of tabs for each page should be changed.

Regards,

Sushil Saini

解决方案

Inorder to change background color of tabs,set the TabControl''s DrawMode to OwnerDraw, and then handle the DrawItem event to draw.

//set the drawmode and subscribe to the DrawItem event
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;




private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            Font f;
            Brush backBrush;
            Brush foreBrush;

            if(e.Index == this.tabControl1.SelectedIndex)
            {
                f = new Font(e.Font, FontStyle.Italic | FontStyle.Bold);
                backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
                foreBrush = Brushes.PowderBlue;
            }
            else
            {
                f = e.Font;
                backBrush = new SolidBrush(e.BackColor);
                foreBrush = new SolidBrush(e.ForeColor);
            }

            string tabName = this.tabControl1.TabPages[e.Index].Text;
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            e.Graphics.FillRectangle(backBrush, e.Bounds);
            Rectangle r = e.Bounds;
            r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
            e.Graphics.DrawString(tabName, f, foreBrush, r, sf);

            sf.Dispose();
            if(e.Index == this.tabControl1.SelectedIndex)
            {
                f.Dispose();
                backBrush.Dispose();
            }
            else
            {
                backBrush.Dispose();
                foreBrush.Dispose();
            }
        }


This[^] post might help.


change the back color of the individual tab pages in the form load event...

TabControl1.TabPages(0).BackColor = Color.White



Hope this will give an idea.


这篇关于Visual Studio 2005中的选项卡控件背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆