标签页标题颜色 [英] tab page header color

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

问题描述

HI



i尝试使用此代码更改标签控件中标签页的标题颜色



  Dim  g  As  Graphics = TabControl1.CreateGraphics 

Dim rect As Rectangle = Rectangle(((TabControl1.SelectedIndex * TabControl1.ItemSize.Width)_
+ 2 ), 2 ,(TabControl1.ItemSize.Width - 2 ),(TabControl1.ItemSize.Height - 2 ) )
g.FillRectangle(Brushes.Lime,rect)
g.DrawString(TabControl1.SelectedTab.Text, New Font(TabControl1.SelectedTab。 Font,FontStyle.Bold),Brushes.Red,rect)< / pre >


此代码

更改标题颜色 选中标签页

如何 使用此代码 new 方式 更改颜色 标签页 3 JUST ??? < / pre >

解决方案

  private   void  tabControl1_DrawItem( object  sender,DrawItemEventArgs e)
{
// 此标签控件中的每个标签按钮都会调用此事件

// 首先使用基于当前选项卡的颜色绘制背景

// e.Index是TabPages集合中标签的索引。
switch (e.Index)
{
case 0
e.Graphics.FillRectangle(< span class =code-keyword> new SolidBrush(Color.Red),e.Bounds);
break ;
case 1
e.Graphics.FillRectangle( new SolidBrush(Color.Blue),e.Bounds);
break ;
默认
break ;
}

// 然后绘制当前标签按钮文字
Rectangle paddedBounds = e.Bounds;
paddedBounds.Inflate(-2,-2);
e.Graphics.DrawString(tabControl1.TabPages [e.Index] .Text, this .Font,SystemBrushes.HighlightText,paddedBounds);

}



将DrawMode设置为'OwnerDrawnFixed'意味着每个标签按钮必须大小相同(即固定)。



但是,如果要更改所有选项卡按钮的大小,可以将选项卡控件的SizeMode属性设置为Fixed,然后更改ItemSize属性。



谢谢&注意

假:)


谢谢你的回答



但是我想改变标题标签页3的颜色与点击按钮!不是默认!


更多信息请参阅此链接:

使用自定义视觉样式的MBTab控件 [ ^ ]

通过重绘微软面板自定义TabControl [ ^ ]

http://www.devcomponents.com/dotnetbar/AdvancedSuperTabControl.aspx [ ^ ]

我希望它会有所帮助您。 :)

HI

i try for change header color of tab pages in tab controls with this code

Dim g As Graphics = TabControl1.CreateGraphics

   Dim rect As Rectangle = New Rectangle(((TabControl1.SelectedIndex * TabControl1.ItemSize.Width) _
                   + 2), 2, (TabControl1.ItemSize.Width - 2), (TabControl1.ItemSize.Height - 2))
   g.FillRectangle(Brushes.Lime, rect)
   g.DrawString(TabControl1.SelectedTab.Text, New Font(TabControl1.SelectedTab.Font, FontStyle.Bold), Brushes.Red, rect)</pre>


this code

change header color of selected tab page

how to use this code or new way for change color of tabpage 3 JUST???</pre>

解决方案

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
    // This event is called once for each tab button in your tab control

    // First paint the background with a color based on the current tab

   // e.Index is the index of the tab in the TabPages collection.
    switch (e.Index )
    {
        case 0:
            e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.Bounds);
            break;
        case 1:
            e.Graphics.FillRectangle(new SolidBrush(Color.Blue), e.Bounds);
            break;
        default:
            break;
    }

    // Then draw the current tab button text
    Rectangle paddedBounds=e.Bounds;
    paddedBounds.Inflate(-2,-2);
    e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, this.Font, SystemBrushes.HighlightText, paddedBounds);

}


Setting the DrawMode to 'OwnerDrawnFixed' means each tab button has to be the same size (ie Fixed).

However if you want to change the size of all tab buttons, you can set the tab control's SizeMode property to 'Fixed' and then change the ItemSize property.

Thanks & Regard
Sham :)


Thank u for ur answer

but i want to change header color of tabpage 3 with click button! not default!


For More Information Please See this Link:
MBTab Control With Custom Visual Styles[^]
Customized TabControl by Repainting Microsoft's Panels[^]
http://www.devcomponents.com/dotnetbar/AdvancedSuperTabControl.aspx[^]
I hope it will help you. :)


这篇关于标签页标题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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