Transparent and interactive form on top of existing one

M

Manuel Ricca

Hello,

I want to create a "glass" effect, where one transparent form is on top
of an existing form, which is full of controls. The idea is to allow
the user to select a part of the screen, by showing a selection
rectangle while the mouse is down. The mouse events must not pass to
the existing form, though.
The tricky part is exactly this: how to catch mouse events on a
transparent form. I already tried 3 different approaches. In each one I
put a solid rectangle in the transparent form. I wish to see only the
rectangle but not the form's background, and still be able to catch
mouse events on the whole trasparent form.

1. Set the top form's BackColor to Color.Transparent: first I had to
subclass it to be able to
SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.UserPaint, true) and set WS_EX_TRANSPARENT on
CreateParams.
This gives unpredictable results; sometimes it shows the rectangle
inside the transparent form, and sometimes it doesn't. Sometimes it
even shows the form's background (!!!)

2. Set the form's Opacity to 0: this hides everything, including the
form and the rectangle. Also, mouse events are not caught in the
transparent form. It's funny that if opacity is 0.1, then mouse events
are caught.

3. Set TransparencyKey to a color and then BackColor to the same color.
This gives the same results as setting Opacity to 0: no show, and no
events.

Has anyone got a clue on how to do this?

TIA,

Manuel Ricca
 
M

Manuel Ricca

Actually method 3 is different from 2 with Opacity=0, because I can
draw on the trasparent form without the stuff that is drawn being
affected by the opacity level. However, regarding mouse events it's the
same; it doesn't respond to them where the form is transparent.

Manuel Ricca
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top