Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a fully transparent winform in C# that is interactive?

Tags:

c#

winforms

I am trying to create a form in C# that is fully transparent, but will not allow clicks to go through it to the other windows below. I have found two methods that were promising, but did not achieve the results I wanted.

The first is by setting the background color and transparency key to the same value. This gives me the transparent form, but clicking goes through.

this.BackColor = Color.Red;
this.TransparencyKey = Color.Red;

The other thing I tried is to set the opacity of the form to 1%. This creates the effects I wanted - almost. I get a 99% transparent form, but there is a slight color alteration to whatever is underneath the form. Since the app I am making is meant to be used in color-sensitive context (graphic design and such), even a tiny alteration of the colors is unacceptable. So I turn to you, dear SO. Can this be done?

like image 643
Ermir Avatar asked Jun 19 '13 16:06

Ermir


2 Answers

I have found the solution, and I am sharing it with you guys as well.

The answer was quite simple: I set: this.TransparencyKey = Color.Lime;

And then I used a 1x1px Lime PNG as the background image. This also has the added benefit of not obscuring the form border and title bar. I will remove them later, but at the moment, it's useful to know where the form is located.

like image 103
Ermir Avatar answered Sep 18 '22 11:09

Ermir


I found a solution to this completely by accident.

I wanted a click through transparent window and got it by using the answer in this SO question:

C# cursor highlighting/follower

That answer uses a transparency filter of LightGreen, but I thought that I might need to use that Color so I changed it to AliceBlue and click through stopped working. I switched back to LightGreen and it started working again.

like image 29
OrangeKing89 Avatar answered Sep 20 '22 11:09

OrangeKing89