transparent  picturebox

Posted on 2006-06-04
Medium Priority
Last Modified: 2012-08-13
Hi, i am making an interface using vc.net. 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
  • 2
LVL 49

Expert Comment

ID: 16830167
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

ID: 16830479
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 VC.net not VB.net 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 Vc.net.

Thank you agian

LVL 49

Accepted Solution

DanRollins earned 1400 total points
ID: 16836938
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

862 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