2

I am experimenting and trying to figure out DWM and Windows Aero. So far, I think I pretty much have it, all except for some strange reason, when I click the thicker part of my form, my click goes right through it, and I can't figure out how to stop it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int en;
        public Form1()
        {
            InitializeComponent();
            DwmIsCompositionEnabled(ref en);
            if (en > 0 && System.Environment.OSVersion.Version.Major >= 6)
            {
                en = 0;
                MARGINS mg = new MARGINS();
                mg.m_Buttom = 0;
                mg.m_Left = 0;
                mg.m_Right = 0;
                mg.m_Top = 25;
                DwmExtendFrameIntoClientArea(this.Handle, ref mg);
                this.BackColor = Color.Magenta;
                this.TransparencyKey = Color.Magenta;
            }
        }
        public struct MARGINS
        {
            public int m_Left;
            public int m_Right;
            public int m_Top;
            public int m_Buttom;
        }
        [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
        public extern static int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margin);
        [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
        public extern static int DwmIsCompositionEnabled(ref int en);

    }
}
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Sean
  • 8,401
  • 15
  • 40
  • 48

1 Answers1

0

That's because you have

 this.BackColor = Color.Magenta;
 this.TransparencyKey = Color.Magenta;

Remove line with transparency. This also happens in WindowsForms. I think it's by design, not bug.

Tomas Voracek
  • 5,886
  • 1
  • 25
  • 41
  • The problem is that I need to expand my form and use Aero to do so, and the only way I have found to do this is by transparency. – Sean Jan 07 '11 at 22:42
  • 1
    @Sean: I think that extending glass into the window only works for layered (`WS_EX_LAYERED` style) windows, and one of the side effects of `TransparencyKey` is to make the window layered. You need to find another way to make the window layered. – Ben Voigt Jan 08 '11 at 01:13