Backcolor of tabcontrol-tabpages area?

  • Thread starter =?ISO-8859-15?Q?Roland_M=FCller?=
  • Start date
?

=?ISO-8859-15?Q?Roland_M=FCller?=

Hello Group,

i want to color the tabpages of a tabcontrol-tabpages area. Overwriting
the DrawItem event and works well coloring the tabs itself.

But the tabcontrol itself has an grey frame where the tabpages are meant
to be. How can i color this area of the control?
tabControl.DisplayRectangle does not give me this area!


Thanks in advance, Roland
 
T

Techno_Dex

Not sure if it will work, but try looping through the Controls collection on
the tabpage to see if anything like a Panel is there that you can paint on.
 
M

Mick Doherty

The System.Windows.Forms.TabControl does not allow you to change the
BackColor to anything other than SystemColors.Control.

You need to draw the entire TabControl yourself in order to do this. You
will find a simple example on my TabControls page as well as a couple of
more complete examples on codeproject.

http://www.dotnetrix.co.uk/tabcontrols.html
http://www.codeproject.com/cs/miscctrl/flattabcontrol.asp
http://www.codeproject.com/dotnet/CustomTabControl.asp

If you don't want all the hassle of drawing the control yourself, then you
will also find TabControlEX on my controls page, which allows you to change
the backcolor by simply setting the BackColor property. It also has several
other modifications which are frequently asked for.
http://www.dotnetrix.co.uk/controls.html
 
M

Mick Doherty

....or so long as you're TabControl is not XP Themed, you could do something
nasty like:

Public Class MyTabControl
Inherits System.Windows.Forms.TabControl

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = &H14 Then 'WM_ERASEBKGND
Dim g As Graphics = Graphics.FromHdc(m.WParam)
Dim clipregion As New Region(Me.ClientRectangle)
Dim pageBounds As Rectangle = Me.DisplayRectangle
pageBounds.Inflate(3, 3)
clipregion.Exclude(pageBounds)
For id As Int32 = 0 To Me.TabCount - 1
clipregion.Exclude(Me.GetTabRect(id))
Next
g.Clip = clipregion
g.Clear(Color.Red)
g.ResetClip()
g.Dispose()
End If
End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top