TabControl and Transparency

  • Thread starter Thread starter Bob Dankert
  • Start date Start date
B

Bob Dankert

(Notes: This is with DotNet 1.1, Windows XP SP2)
I have a tabcontrol located on a form where the form has a background image.
Ideally, I would like to have the background near the upper-portion of the
tabs be transparent so the image of the form will show through. Initially,
this seemed to work fine without modification. However, after using it
briefly, it is apparent that the tabs flicker immensely when you move the
mouse over them. To solve this, I assumed I would be able to owner-draw the
tabcontrol, however by specifying this the entire top-section of the
tabcontrol remains the drab gray color and draws the rectangle to the right
of the tabs. So, this seems to work even less than had I let the control
draw itself.

Doing a quick newsgroup search, I found two threads where this has been
reported back in 2002 and a Microsoft representative posted that this was a
bug that would be addressed. Being that this is almost three years later, I
am hoping there is a known workaround other than overriding OnPaint and
OnPaintBackground (or at least an example of how to sucessfully override
these, as this can be a daunting task).

Newsgroup posts from 2002 for reference:
http://groups-beta.google.com/group...bcontrol+transparency&rnum=1#e01dc8403fadc8e1

http://groups-beta.google.com/group...bcontrol+transparency&rnum=4#c80ffc9efc71243c

Thanks, any help would be appreciated.

Bob Dankert
 
As a note, I am not using HotTrack - I turned this both on and off and had
the same issues either way.

Bob
 
When using a BackgroundImage property the painting is very slow.
The TabControl does not support Transparent Background and AFAIK this is not
going to be addressed, although Visual Styled TabControls do appear to have
a Transparent Background.

You'll find a TabControl on my downloads page that does support Transparent
Background, but does not support XP Visual Styles. It also supports one or
two other frequently requested features.
http://dotnetrix.co.uk/download/TabControlEX.dll

If all you want is to ease the flicker then add the following code to your
form:
\\\
'Modify Sub New as follows
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
setstyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, True)
End Sub


'and add this code to the form
Private BackImage As Bitmap

Private Sub MainForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not BackgroundImage Is Nothing Then
BackImage = New Bitmap(Me.BackgroundImage)
Me.BackgroundImage = Nothing
End If
End Sub

Protected Overrides Sub OnPaintBackground(ByVal pevent As _
System.Windows.Forms.PaintEventArgs)
If BackImage Is Nothing Then
MyBase.OnPaintBackground(pevent)
Else
pevent.Graphics.DrawImage(BackImage, Point.Empty)
End If
End Sub
///
 
Back
Top