transparent  picturebox

Posted on 2006-06-04
Last Modified: 2012-08-13
Hi, i am making an interface using i am using multiple picturebox in my form eac of which has an image and all of them have the same parent (panel1). all these pictreboxes have tp move around and sometimes they pverlap. the problem is when they overlap ,eventhought i set the backgroud color to transparent, i only got the background of their parent not each other. so can i make them become transparent even for each other.

Thanks for however reply.

Question by:zahersbg
    LVL 49

    Expert Comment

    The behavior you describe is documented here:
         Note:  If there is another control between the control and its parent, the current
         control will not show the control in the middle.
         OnPaintBackground will simulate transparency by asking its parent control to
         paint the background. This is not true transparency.

    One source says it is nevertheless possibl if you do...
        yourPicture.SetStyle(ControlStyles.Opaque, false); // optional
        yourPicture.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        yourPicture.BackColor = Color.FromArgb(0,0,0,0);
    ...but I did not verify that.

    Another says to also set the UserPaint style:
        yourPicture.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint , true);

    Another source says that using this to set the WS_EX_TRANSPARENT style works (put this in the constructore of you derived control):

     protected override CreateParams CreateParams
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
        return cp;

    and  set style to opaque:
       this.SetStyle(ControlStyles.Opaque, true);

    But the underlying object do not get redrawn unless you Invalidate them first (do it from the "lowest" to the "highest")

    Another partial solution is described here:

    The Expert in this Q recommends using a borderless form rather than a PictureBox:

    I hope that helps.
    -- Dan

    Author Comment

    Thank you for your reply Dan.
     I tried what you have suggested but with no hope excpet the WS_EX_TRANSPARENT (because i am using not so i did not know how to convert this code to VC). I am still getting the same result, beside i can not use the borderless form, becasue i am interacting withthe main form and when i do that the focus will be on the main form and the borderless form will diappear. So is there anyway to make sure that this possible to be done or it is just the limatation of

    Thank you agian

    LVL 49

    Accepted Solution

    In your PictureBox-derived object, you should be able to override the CreateParams attribute using the normal mechanism... eg, the ClassWizard.  I'm not at a .NET enabled VS box right now, so I can't provide the steps, but it should be pretty straightforward ro add the WS_EX_TRANSPARENT extended style bit, given the example code.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now