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
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