HI,
i'm working on c#.net 2008 edition and i want if we can control the opacity of a picture box on the form differently from the form itself i.e. if we can make the form transparent while still be able to see the picture box on it fully visible.
i did try several things but all i could manage was this...

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
this.BackColor = Color.FromArgb(0,Color.Black);

but it won't work good. Any help?

Unfortunately there is no way to make a Form semi-transparent and keep controls within it opaque (as far as I know).

The hackery way to do it is to have two forms, one semi-transparent, and the other one on top to hold the opaque controls. However I don't recommend this since it is really messy.

There is a third party control library called SemitranparentForm.dll (StForm). By referring this assembly and inheriting the StForm we can get Opaque controls on Semitransparent form. A demo application is available. Use the below link for more information.


http://www.stforms.net

I don't think the OP was looking for a link to a product. But its a neat product I will admit. There are very few ways this can be done, you can custom draw your controls to the screen, which is complicated and can get very messy, but since its not drawn on the form. It can be whatever Opacity you want.

here's where the multiple forms concept comes to play. its not really that messy. its not that hard to do, It often yields great results. And using a "Form" overlay for your main form can get the job done.

it doesn't actually have to be a "Form" but just a separate "window" windows OS treats everything as a window, you just need to create another window, with its own handle, that can be modified separately. and the easiest way to do this is with a new form.

so. I suggest 2 methodologies for this.

1. if you don't intend to need to reuse, or use multiple controls with this feature, then just create a new form, with a formborderstyle of none, add the control you need on it. give it a transparent background. and create a public property that exposes the control.

Then in your original form, create an instance of the new form, set it where it needs to be, just as if it were just a control, then use and set the properties and methods of the control property you created just as if it were a normal control. and there you get the desired effect.

2. now if you want re-usability. then you can actually create a control that can be dropped onto a form. with a property of standard control types, that will automatically create the new form, set its position, and expose its control the way you want it. It wouldn't be that hard. and would be actually quite useful.

The hardest part, would be getting good transparency from the top controls. you would need them to all be custom controls that support transparent backgrounds. Exept the picturebox control, that would be easy because its a rectangle, so have it fill the control form, and adjust the control form's opacity. and you are golden.

I have a killer headache right now, and a ton of stuff to do for independence day, so I can't mock you up anything right now. but if you are still having trouble after the weekend. I can devote some time into showing what could be done in terms of this.

good luck and happy coding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.