0
votes

I want to create a WinForm which has a normal frame but a large portion of the application transparent. I've run into an issue whereby after a maximize and restore down of a window, the frame border is no longer clickable -- clicks simply pass through to the application behind my application. I've been able to reproduce this with a trivial WinForms app by doing the following:

  1. Create a new WinForms application.
  2. Set the TransparencyKey and the BackgroundColor of the default form to the same color.
  3. Run the app.
  4. Click the maximize button of the running form.
  5. Click restore down.
  6. Form border no longer clickable (though sometimes I seem to get a 1px clickable border along one side).

There's a ton on the web about transparent forms and controls, but I found nothing on this bug. Given its simplicity to reproduce, I doubt I'm the first to run into this. Any ideas for getting around it?

1
I have tried your example and I am not finding any problems. After maximizing, when I restore the window, the border is still resizable. Perhaps I don't fully understand your problem, but from my experience it doesn't seem there is a bug. (I would comment rather than answer, but I don't have enough rep)Michael
After reproducing this on multiple machines, it appears that the common denominator is Aero. Aero themes and form transparency do not seem to play nicely together.SkiDrew

1 Answers

-1
votes
const int WM_SYSCOMMAND = 0x0112;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
const int SC_RESTORE = 0xF120;
const int SC_TOP = 0xF003;
const int SC_LEFTTOP = 0xF004;
const int SC_RIGHTTOP = 0xF005;
const int SC_DBCLICKTITLEBARMAX = 0xF122;
protected override void WndProc(ref Message m)
{
    base.WndProc(ref m); 
    if (m.Msg == WM_SYSCOMMAND)
    {
        int sc = m.WParam.ToInt32();
        if (sc == SC_RESTORE | sc == SC_LEFTTOP | sc == SC_TOP | sc == SC_RIGHTTOP | sc == SC_DBCLICKTITLEBARMAX )
        {
            FormBorderStyle oldvalue = this.FormBorderStyle;
            this.FormBorderStyle = FormBorderStyle.None;
            this.FormBorderStyle = oldvalue;
        }
    }
}