2
votes

It seams to be a bug, if you change a Form size to a previously transparent region, mouse events will no longer be detected on it.

How to reproduce it:

  • Create a new Windows form project
  • Set Form1 TransparencyKey to Magenta
  • Add a Panel to Form1 and config it as:
    • Dock fill
    • BackColor to Magenta

Run, now try to change the Form size, if you reduce it (enough so the new border will be placed over a current transparent region), the mouse will no longer "detect" the window border on that side. If you minimize/restore the window, it will work again. How can I fix that? I tried Refresh on Form Layout/Resize event, but it didn't work.

1

1 Answers

3
votes

Just to confirm, yes this is a bug in the current Aero implementation on Windows 8.1. Possibly before. Been around for quite a while, seems like it is a pretty structural problem. It is part of a set of bugs related to layered windows with the transparency key set, and getting the mouse to be transparent to such a window, it also doesn't work properly with certain color selections for the key. In this specific case, it inappropriately makes the frame transparent to clicks as well.

Hard to give specific advice, this does require calling Microsoft Support to get ahead. Technically you can take advantage of another bug, the window is never transparent to mouse clicks when you pick, say, Red as the transparency key:

    public Form1() {
        InitializeComponent();
        this.TransparencyKey = panel1.BackColor = Color.Red;
    }

Solves the bug you are dealing with, but of course disables mouse transparency completely. A workaround you almost definitely won't like is:

    protected override void OnResizeEnd(EventArgs e) {
        base.OnResizeEnd(e);
        this.RecreateHandle();
    }

Too noticeable. Programmers are starting to take advantage of these bugs, sometimes they want such lack of transparency intentionally. Makes you wonder how Microsoft is ever going to get this fixed without breaking some program. Not pretty.