0

In c# winforms I have created a click through form using the code I found from this question. The code is below:

    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);

    [DllImport("user32.dll")]
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("user32.dll", SetLastError = true)]
    public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]

    public static extern bool GetWindowRect(IntPtr hwnd, out RECT IpRect);

    public static RECT rect;

    public struct RECT
    {
        public int left, top, right, bottom;
    }

    private void Form1_Shown(object sender, EventArgs e)
    {
    int initialStyle = GetWindowLong(this.Handle, -20);
    SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
    }

However, In the answers there was no explicit description on how to undo this change with code, to make the form clickable again. I was wondering if anyone knew how to do that.

  • I only go for TransparencyKey using either Color.Fuchsia or to switch some random color .. – TaW Jul 13 '22 at 18:47
  • 2
    Make the *initialStyle* a member of the form class, now you can simply call SetWindowLong again. This is not the right way to do it, [handle WM_NCHITTEST](https://stackoverflow.com/a/14430948/17034) instead, return HTTRANSPARENT (-1). – Hans Passant Jul 13 '22 at 18:55
  • 3
    https://stackoverflow.com/a/32210591/17034 – Hans Passant Jul 13 '22 at 19:08

0 Answers0