10

I've created a semi-transparent form. I'd like for people to be able to click on the form area, and for form not handle the click. I'd like whatever is underneath the form to receive the click event instead.

caesay
  • 16,404
  • 14
  • 91
  • 156
  • possible duplicate of [Click through transparency for Visual C# Window Forms?](http://stackoverflow.com/questions/112224/click-through-transparency-for-visual-c-window-forms) – Joey May 09 '10 at 16:09
  • What will underneath the form? – Ikaso May 09 '10 at 16:10

1 Answers1

16

You can do this with SetWindowLong:

int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);

There are a few magic numbers in here:

  • -20GWL_EXSTYLE

    Retrieves the extended window styles.

  • 0x80000WS_EX_LAYERED

    Creates a layered window.

  • 0x20WS_EX_TRANSPARENT

    Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted.

There are numerous articles all over the web on how to do this, such as this one.

Joey
  • 330,812
  • 81
  • 665
  • 668