在不透明度较低的情况下单击winForm

时间:2018-08-12 06:13:48

标签: c# winforms

我有一个带有TrackBar的c#winForm,可更改不透明度。 我希望能够在不透明度小于0.2时单击表单 有可能吗?

这就是我尝试过的(我从互联网上获取的大部分代码):

    [DllImport("user32.dll", SetLastError = true)]

    private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]

    static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

    [DllImport("user32.dll")]

    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

    public const int GWL_EXSTYLE = -20;

    public const int WS_EX_LAYERED = 0x80000;

    public const int WS_EX_TRANSPARENT = 0x20;

    public const int LWA_ALPHA = 0x2;

    public const int LWA_COLORKEY = 0x1;

    private void trackBar1_Scroll(object sender, EventArgs e)
    {
        this.Opacity = trackBar1.Value / 100.0;


        uint tmp = GetWindowLong(this.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED ^ WS_EX_TRANSPARENT;


        if (trackBar1.Value < 20)
            SetWindowLong(this.Handle, GWL_EXSTYLE,

            (IntPtr)(GetWindowLong(this.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED ^ WS_EX_TRANSPARENT));

        else
        {
            SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)tmp);

        }



    }

0 个答案:

没有答案