Is it possible to have the Tabs of a Tab Control with a picture or colour?
Printable View
Is it possible to have the Tabs of a Tab Control with a picture or colour?
You can have tab pages with icons besides the tab text. Drop a ImageList control from Toolbox and then add images to it. Then set ImageList property of TabControl to this ImageList control that you dropped on form. Now set the ImageIndex property of each tab page which will display the icons from ImageList control of that ImageIndex.
thanks Deepak,
How come we can change the colour of the TabPage but not the button also? Anyway I can do that?
Select the client area of a TabPage where you drop your controls and change the BackColor property to the desired color.
Hi Deepak,
It's the Tab button I need to change to be like the Tab Page. Have a look at the pic. Is it possible to have the button where I have L/A, L/ABook etc in light green also?
Angelica,
The Tab Control in .NET does not expose properties to change its back ground and foreground color. This can be achieved by overriding the DrawItem event of the control. Following are the steps involved to do the same.
1. Set the TabControl's DrawMode to OwnerDraw
2. Handle the DrawItem event to draw things yourself
vb.net Code:
Private Sub TabControl1_DrawItem( _ ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs _ ) Handles TabControl1.DrawItem Dim g As Graphics = e.Graphics Dim tp As TabPage = TabControl1.TabPages(e.Index) Dim br As Brush Dim sf As New StringFormat Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2) sf.Alignment = StringAlignment.Center Dim strTitle As String = tp.Text br = New SolidBrush(tp.BackColor) g.FillRectangle(br, e.Bounds) br = New SolidBrush(tp.ForeColor) g.DrawString(strTitle, TabControl1.Font, br, r, sf) End Sub
ok Deepak, many thanks