Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is a method to put two control in the same location and opacity the control on the front.?

ex:-
Control A (in the back): Button , opacity 100%, location 300;240
Control B (in the Front): Panel or any other, opacity 60%, location 300;240

What I have tried:

i tried to this:
Color.FromArgb(120, Color.Black);


but it works only if there are no controls in the back.
Posted
Updated 24-Dec-22 3:01am

That's because, in Windows Forms, Transparent isn't. When you set the backcolor of a control to Transparent, what you are really doing is telling the control to take on the background properties of its container, likely your Form. You cannot see the Button control behind the Panel.

Opacity does NOT make a control transparent. It makes what you are drawing partially transparent, but it does not make the drawing surface of the control transparent. To get around this, you would have to make your own version of the Panel control so you get complete control over how the Panel is painted.

For an example, see Creating a .NET Transparent Panel | CodeGuru[^]

You have another problem. The Panel control you're going to create will cover the Button so any mouse clicks will go to the panel, not the button! The Panel is visually transparent to you, not the mouse.
 
Share this answer
 
Comments
BillWoodruff 24-Dec-22 9:01am    
+5
To get the kind of transparency you want in Win Forms, use separate Forms, each of which can have its opacity set separately. Set the forms' DoubleBuffer Property to 'true. Using Forms you get run-time movability "free" depending on FormBorderStyle, and other settings.

The hacks that can be used to simulate a kind-of transparent panel are, imho, not that useful, and may have weird refresh behavior when their host Forms are moved or resized.

You'll have to manage the forms' position and z-order, and, as Dave points out, opacity setting does not let a mouse-click "pass through."
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900