【问题标题】:Why can I clickthrough my form?为什么我可以点击我的表单?
【发布时间】:2011-01-07 22:34:42
【问题描述】:

我正在试验并试图找出 DWM 和 Windows Aero。到目前为止,我认为我几乎拥有它,除了一些奇怪的原因,当我点击表单的较厚部分时,我的点击直接穿过它,我不知道如何阻止它。

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);

    }
}

【问题讨论】:

    标签: c# winforms aero hittest dwm


    【解决方案1】:

    那是因为你有

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

    移除透明线。这也发生在 WindowsForms 中。我认为这是设计使然,而不是错误。

    【讨论】:

    • 问题是我需要扩展我的表单并使用 Aero 来这样做,而我发现这样做的唯一方法是通过透明度。
    • @Sean:我认为将玻璃延伸到窗户中只适用于分层(WS_EX_LAYERED 风格)的窗户,TransparencyKey 的副作用之一是使窗户分层。您需要找到另一种方法来使窗口分层。
    猜你喜欢
    • 2016-07-31
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    相关资源
    最近更新 更多