Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Does anyone know how to make a transparent tabpage?

Does anyone know how to make a transparent tabpage?

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Flack
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • F 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, -Flack

      C Offline
      C Offline
      Carlos H Perez
      wrote on last edited by
      #2

      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.

      F 1 Reply Last reply
      0
      • C 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.

        F Offline
        F Offline
        Flack
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups