Click windows transparent form C#

Asked

Viewed 194 times

1

I have a transparent windows form for drawing on other screens. For transparency, I used the following code:

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

It worked for a while, but now it doesn’t recognize the clicks on the screen, it’s like clicking through it. Coincidentally or not, it stopped working after a Windows 10 upgrade, and works on other computers.

It wasn’t a modification of the code that caused it to crash, because even going back to earlier versions of the project, where the click was recognized, doesn’t work anymore. Is there any other way to make the window transparent? Follow a print of the program, so you can understand what the application is about.

Print da aplicação aberta sobre o navegador

  • 1

    Just posting the code so we can check.

  • The code of the transparency part is there :)

  • I just created a form transparent and works perfectly.

  • This code is inside the constructor method of the single form. Inside this form, there is a panel where things are drawn. The captured events are mouse clicks, and are captured in the panel class. However, my question is not how to solve this code, but how else to make the transparency of a form.

  • If you’ve created a transparent form that works the way I need it, why not put it as an answer?

  • Because I used exactly the code that you have in your question (????)

  • If I understand correctly, you’re doing it the wrong way, the right way would be using an overlay.

  • Okay, and I came here to ask for sure why I have a functional code. Thank you for your help, jbueno, all I needed was someone to test and say that it works what was done here. Surely the application will feel motivated with your words and start to work.

Show 3 more comments

1 answer

2


The behavior you describe is as expected, as you can see in documentation:

When the Transparencykey Property is Assigned a Color, the areas of the form that have the same Backcolor will be displayed transparently. Any mouse actions, such as the click of the mouse, that are performed on the Transparent areas of the form will be transferred to the windows Below the Transarea parent.

Translating

When a color is assigned the Transparencykey property, the form areas that have the same background color will be displayed transparently. Any mouse actions, such as a mouse click, that are executed in the transparent area of the form will be transferred to the window behind the transparent area.

In tests I’ve done here, if I use Red as BackColor and TransparencyKey i have the same behavior you describe in 64 bit Windows 10, where I haven’t installed the last update, already on a virtual machine running Windows 7 SP1 it works as described in the documentation.

As a test I changed the color to Magenda and then in my Windows 10 started to behave as the documentation also describes.

So I would say it was some bug that was fixed with the last Windows 10 update.

  • Yeah, it only worked here with the same red color, the rest of the colors the click was not captured. I hadn’t seen this part of the documentation, but I imagined it was a bug, it doesn’t make sense one color work and all the others don’t. But it worked the way they wanted it to with the color red, because believe the intern who said it would go wrong, right? Anyway, do you have any suggestions on how to do this another way?

  • Ok, problem solved. I created an opaque form from behind and it makes click events can be captured.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.