Does anyone know how to make a transparent tabpage?
-
Hello, I have a tab control on my main form and my form has an image as its background. Is there any way for me to have the tabpages be transparent so that you can see the forms background image behind it? It works with my buttons but not with the tabpages. I tried:
BackColor = Color.Transparent;
but that didnt do anything. If anyone can help me out that would be great :-D Thanx, -Flack -
Hello, I have a tab control on my main form and my form has an image as its background. Is there any way for me to have the tabpages be transparent so that you can see the forms background image behind it? It works with my buttons but not with the tabpages. I tried:
BackColor = Color.Transparent;
but that didnt do anything. If anyone can help me out that would be great :-D Thanx, -FlackThe .NET TabControl is actually a wrapper of the "PropertySheet" control that first appeared in the Common Control Library Version 4.71. It is not a "Windowless" control that you can just make transparent by setting some flag. What you can do is to trick the user's eye into thinking that the TabPage is transparent by drawing the portion of the Form's background image underneath the TabPage. This will make the TabPage --not the TabControl-- seem like it has a transparent background. Out of my own curiosity I just spent a mere 5 minutes putting together a sample that does this. Here is the code I used on the Paint handler for one of the TabPages: private void tabPage2_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Image backImage = BackgroundImage; TabPage tp = (TabPage)sender; if ( backImage != null ) { Graphics g = e.Graphics; Rectangle tabPageBounds = tp.Bounds; Rectangle screenTabPageBounds = tp.RectangleToScreen(tabPageBounds); Rectangle finalRect = RectangleToClient(screenTabPageBounds); g.DrawImage(backImage, new Rectangle(0, 0, tp.Width, tp.Height), finalRect.Left, finalRect.Top, finalRect.Width, finalRect.Height, GraphicsUnit.Pixel); } } This probably could be improved but it is something just off the top of my head. Here is a picture of what the result looks like --not perfect but perhaps close to what you are looking for--. Transparent TabPage Regards, Carlos H. Perez.
-
The .NET TabControl is actually a wrapper of the "PropertySheet" control that first appeared in the Common Control Library Version 4.71. It is not a "Windowless" control that you can just make transparent by setting some flag. What you can do is to trick the user's eye into thinking that the TabPage is transparent by drawing the portion of the Form's background image underneath the TabPage. This will make the TabPage --not the TabControl-- seem like it has a transparent background. Out of my own curiosity I just spent a mere 5 minutes putting together a sample that does this. Here is the code I used on the Paint handler for one of the TabPages: private void tabPage2_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Image backImage = BackgroundImage; TabPage tp = (TabPage)sender; if ( backImage != null ) { Graphics g = e.Graphics; Rectangle tabPageBounds = tp.Bounds; Rectangle screenTabPageBounds = tp.RectangleToScreen(tabPageBounds); Rectangle finalRect = RectangleToClient(screenTabPageBounds); g.DrawImage(backImage, new Rectangle(0, 0, tp.Width, tp.Height), finalRect.Left, finalRect.Top, finalRect.Width, finalRect.Height, GraphicsUnit.Pixel); } } This probably could be improved but it is something just off the top of my head. Here is a picture of what the result looks like --not perfect but perhaps close to what you are looking for--. Transparent TabPage Regards, Carlos H. Perez.
Thanx for the help Carlos. I have another question now. If my tabpage had a scroll bar, and I still wanted a transparent effect, is my only option to redraw the image each time the user scrolls? That is what I just tried and it seems like a lot of calls to redraw the image. Is there any other, more efficent way? Again, thanx for the help, -Flack