I'm currently writing a custom-designed tab control. I created my own control instead of o开发者_开发知识库wner-drawing the TabControl because I figured it'd be faster and more flexible. My tab control styles itself after the VS2008 tab control; that is, when a tab is selected, part of that tab is in front of other, unselected tabs.
My tab control consists of a Panel containing all of my TabButton objects which are the actual tabs themselves. I've set the TabButton to be transparent like so:
public TabButton()
{
...
SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
this.BackColor = Color.Transparent;
}
However, when the tab is selected and in front of another tab, the portion of the unselected tab that should appear behind the portion of the selected tab is not rendered. It's the standard SystemColors.Control
color that fills in the rest of the clipping rectangle for the selected button.
How can I achieve proper transparency in my custom control?
Also: TabButton inherits Control, that's why I needed to use SetStyle
in order to use transparency.
-Eric Smith
Have a look at this: http://saftsack.fs.uni-bayreuth.de/~dun3/archives/creating-a-transparent-panel-in-net/108.html
Last I was in .NET Windows Forms it wasn't readily apparent that you needed to do some of these psuedo hacks to get transparency to work. I'm not sure if they changed it in the last ~3 years, but I do remember doing something like this. I would try explicitly not drawing a background first.
精彩评论