Results 1 to 3 of 3

Thread: Panel Backcolor Transparent issue. - How to make Panel Transparent

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    UAE
    Posts
    191

    Panel Backcolor Transparent issue. - How to make Panel Transparent

    Name:  Transparent.jpg
Views: 13496
Size:  53.7 KB

    Hello Guys,
    Hope you are doing well..
    I have attached an image. I have developed a project where user can do drawing and add images and kinda MSPaint or Photoshop. I have inherited all controls from Panel.
    After lot of work on project I have an issue that I have form(or any container/parent) with background image. After that I will add one Panel with background color orange.

    Now I have a Form with background image and a panel with back color. Over that Panel1(Parent is Form) I have one more panel (Panel2) where I want to set Transparency so It should show Panel1 from it but instead of that it shows Form Background.

    If you still not understood here are steps.
    Form1 : Background Image=Image1
    Added Panel1 with Backcolor = Orange, Panel1.Parent=Form1, Panel1.Left= 200,Panel1.Top=200, Panel1.width= 400,Panel1.height=120
    Added Panel2 with Backcolor = Transparent, Panel2.Parent=Form1, Panel2.Left=300, Panel2.top=20, Panel2.Height =500, Panel2.width =120


    My Question is How can I see Objects behind the Transparent Panel when Transparent Panel shows Parent's Backcolor/image.
    Each New Difficulty Is Best Opportunity,
    If You Ignore Solving It,
    You Lost Your Life's Best Opportunity.
    _______________________________________
    Dynamic Property value assignment - C#
    TCP client/server connection

    CatchIt-Game
    Fortunes
    SQL Tutorials

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Panel Backcolor Transparent issue. - How to make Panel Transparent

    Quote Originally Posted by ishrar View Post
    My Question is How can I see Objects behind the Transparent Panel when Transparent Panel shows Parent's Backcolor/image.
    One way would be to set those objects to the front and/or set the transparent panel to the back.

    object2.SendToBack()
    object1..BringToFront()
    etc...

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Panel Backcolor Transparent issue. - How to make Panel Transparent

    Hi ishrar,

    Control Transparency in Windows Forms means "show me the Parent control". There is no way round that, and juggling the Z-order will make no difference. For example, you could make the orange panel (I'll call it OrangePanel) the Parent of the front panel (FrontPanel) like this:
    Code:
    FrontPanel.Parent = OrangePanel
    FrontPanel.Left -= OrangePanel.Left
    FrontPanel.Top -= OrangePanel.Top
    You will then see the Orange panel, but the rest of the front panel will be clipped at the orange panel's bounds. You wouldn't be able to see the container background through your front panel. It's possible to think of some tricks -- hacks as some would call them. You could show a second copy of the FrontPanel behind OrangePanel, for example. If the user can reposition or resize the front panel, you would have to code its Move and Resize event handlers to keep the copy the same size and position. On the other hand, it could get rather complicated and perhaps unworkable if there are several superimposed images or multiple layers.

    So maybe you should consider alternatives. One possibility is to use graphics to superimpose the images instead of relying on Panels and their limited transparency. You could draw all the images using Graphics.DrawImage and the borders with Graphics.DrawRectangle. You could do the graphics in the Paint event handler of the container control; or you could paint everything on a bitmap and show that as the container's background image.

    Another alternative would be to use WPF, in which transparency works with fewer surprises. Making a single WPF window with a few controls isn't hard, and it's even possible to combine it with Windows forms in a hybrid solution (see the "shaped form" link in my signature). But if you don't already know WPF, I suspect it would take a huge amount of learning to port your entire program to WPF.

    BB

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width