By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,910 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,910 IT Pros & Developers. It's quick & easy.

Transparent user control with click through to the control below

P: n/a
I'm trying to create a usercontrol that is transparent, both visibly and to
mouse clicks.

I can make the usercontrol visibly transparent by setting the
SupportsTransparentBackColor style and providing some additional processing
in CreateParams and OnPaintBackground, as detailed here:

http://www.codeproject.com/KB/edit/T...ntTextBox.aspx

This works fine, but if I click the transparent part of my control, the
mouse click is still received by my usercontrol instead of by the control
that is behind it. Is there a way to make clicks fall through the
transparent parts of the control to whatever is underneath?

Thanks,

--

(O)enone
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It sounds like you're attempting to either dynamically add the user
control or make it scalable by not having the user control refer to a
specific button underneath. The only idea I can think of without
seeing the project is to make the usercontrol some kind of container
and when it receives a click event to hit something on the underlying
control.

For instance if you had an extended panel control that only could
contain buttons and when it was clicked it would loop through every
button and fire the Click event.

You could also do what ASP.NET does with most of their controls that
have to link together and feed your usercontrol the ID of the item
that needs to be clicked and dynamically click it that way.

Another option is to have the usercontrol throw an event to the main
form when its been clicked that says its been clicked and on that
event fire the click code of the underlying control.

Jun 27 '08 #2

P: n/a
cfps.Christian wrote:
[...]
Another option is to have the usercontrol throw an event to the main
form when its been clicked that says its been clicked and on that
event fire the click code of the underlying control.
Thanks for the suggestions. I didn't perhaps clarify in my original post
that the control will be moving around my form, and exactly what's
underneath it could therefore change. I did consider having the control fire
an event back to its containing form telling it about clicks that it wasn't
interested in, but then I would have to go to all the effort of working out
what control (if any) was actually under the mouse cursor. As there could be
overlapping controls and all sorts, that could be a pain.

In the end I did find a solution however: setting the user control's Region
property. As the shape I want for my control consists only of a series of
rectangles, this works perfectly. The control only renders and responds to
pixels that fall within the defined region; all other parts of the control
show through the form or controls beneath, and mouse clicks are received by
those controls exactly as expected.

--

(O)enone
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.