自定义TabPage标头 [英] Custom TabPage Header

查看:95
本文介绍了自定义TabPage标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想创建一个自定义TabPage标头,可以在其中定义背景色.
只是标题,而不是整个TabPage.

感谢您的帮助

HI everybody,

I would like to create a Custom TabPage Header where I can define the background color.
Just the header, not the whole TabPage.

Thanks for your Help

推荐答案

您可以使用以下代码
You can use the following code
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
        Font TabFont;
        Brush BackBrush = new SolidBrush(Color.White); //Set background color
        Brush ForeBrush = new SolidBrush(Color.FromArgb(86, 125, 177));//Set foreground color
        if (e.Index == this.tabControl1.SelectedIndex)
        {
            TabFont = new Font(e.Font.FontFamily,10,FontStyle.Bold);
            
        }
        else
        {
        TabFont = e.Font;
        }
        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, TabFont, ForeBrush, r, sf);
        //Dispose objects
        sf.Dispose();
        if (e.Index == this.tabControl1.SelectedIndex)
        {
        TabFont.Dispose();
        BackBrush.Dispose();
        }
        else
        {
        BackBrush.Dispose();
        ForeBrush.Dispose();
        }
      }


在此代码中,您可以定义背景色和前景色.

可能会有所帮助,
Theingi Win


In this code you can defined background color and foreground color.

May be helpful,
Theingi Win


如果您之前拥有了自己的控件或自定义了其他控件,则非常简单.否则,可能很难理解这些概念.

您可以在此处找到一个示例 [ ^ ].如果还不够,您可以在Google上搜索客户TabPage控件c#"以获取更多示例.
Simple enough if you''ve made you own controls or customized other control before. Otherwise, the concepts may be a little steep to grasp.

You can find an example here[^]. If that''s not enough, you can google for "Customer TabPage control c#" for more examples.


这篇关于自定义TabPage标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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