- This topic explains about how to color tab in Tab Control in C# programming.
- It will fill color inside the tab control.
- You can assign your own fill color inside the tab control in C#.
- Tools needed: TabControl1 (TabControl1).
Tab Control Class – How to color tab of Tab Control in C#
- Tab Control class manages a related set of tab pages.
- Syntax for Tab Control Class
|
1 2 3 |
[ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] public class TabControl : Control |
- A Tab Control contains Tab pages, which are represented by TabPage objects that you add through TabPages properties.
- The user can change the current TabPage through clicking one of the TabPage.
- You can also change the current TabPage through programmatically.
TabControl.DrawMode Property – How to color tab of Tab Control in C#
- Gets or sets the way that the control’s tabs are drawn.
- Syntax TabControl.DrawMode
|
1 |
public TabDrawMode DrawMode { get; set; } |
- When you set the DrawMode property to OwnerDrawFixed, the TabControl raises the DrawItem event whenever it needs to paint one of its tabs.
- To customize the appearance of the tabs, provide your own painting code in a handler for the DrawItem event.
How to color tab of Tab Control in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; } private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; TabPage tp = tabControl1.TabPages[e.Index]; Brush br = default(Brush); StringFormat sf = new StringFormat(); RectangleF r = new RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2); sf.Alignment = StringAlignment.Center; string strTitle = tp.Text; br = new SolidBrush(tp.BackColor); br = Brushes.Bisque; //assign you own backcolor g.FillRectangle(br, e.Bounds); br = new SolidBrush(tp.ForeColor); br = Brushes.Black; //assign you own forecolor g.DrawString(strTitle, tabControl1.Font, br, r, sf); } } } |

How to color tab of Tab Control in C#
How to color tab of Tab Control in C#






