0

I'm trying to place a transparent and borderless child (WinForm) form on top of another child (WinForm) form that is opaque, but I'd like to retain the ability to directly click on the transparent form. There are a few answers on the web regarding making a transparent form that can be clicked through, but I want to make one that I can click on.

I've found this answer, which shows that setting my transparent form's BackColor and TransparencyKey to something specific like Color.Red achieves the desired behavior. However based on this answer, it seems this behavior between certain Colors and TransparencyKey may actually be a long-running bug.

Ideally I don't want to rely on a bug to achieve a desired effect. What would be a more "appropriate" approach for making a clickable, transparent, and borderless (WinForm) form?


Update (Additional Context):

I'm basically creating a screen pixel previewer for color data extraction.

  • Overlay forms containing captured bitmap(s) of the screen area.
  • Another form that gives a visual indicator for the pixel area being previewed (small black box in the below snapshot). This form is placed above the bitmap forms. I have this form as transparent (to see through to the below bitmaps), but I still want to be able to click on it for event processing.

snapshot

Without the TransparencyKey = BackColor = Color.Red trick, clicking within the small black box causes focus to move to the below bitmap form, which then covers up the small box form and the preview window showing the zoomed view. The purpose of the click is to capture the cursor position for additional processing. I can work around this by immediately giving focus back to the small box + preview forms, but that occasionally causes flicker.

Exergist
  • 157
  • 12
  • What if you simply allow the form to be clicked through, but also record the mouse clicks and call whatever your form is supposed to do with the information? – Martheen Apr 29 '20 at 02:49
  • I'm having trouble imagining how it's supposed to work. Can you describe a little bit more of the use case? Does the transparent window have a combination of transparent and non-transparent elements to it or is it completely 100% transparent everywhere? Are you wanting to intercept clicks to the transparent part? That seems like it might be very confusing if the transparent part of a form received and ate click that I was expecting to click the thing that was visible (behind the transparent form). – Wyck Apr 29 '20 at 03:04
  • @Martheen I updated the above content. Clicking through to the form below the transparent form causes the transparent form to be covered up. Otherwise yes this would work. – Exergist Apr 29 '20 at 16:29
  • @Wyck please see updated details provided – Exergist Apr 29 '20 at 16:36
  • Why not make the small black box a window with a COPY of the pixels below it, rather than actually transparent? – Wyck Apr 29 '20 at 19:51

0 Answers0