コード例 #1
0
        protected void UpdateLayered()
        {
            IntPtr dC      = Win32Interop.GetDC(IntPtr.Zero);
            IntPtr hDC     = Win32Interop.CreateCompatibleDC(dC);
            IntPtr zero    = IntPtr.Zero;
            IntPtr hObject = IntPtr.Zero;

            Render(Graphics.FromImage(feedbackImage));
            try
            {
                zero    = feedbackImage.GetHbitmap(Color.FromArgb(0));
                hObject = Win32Interop.SelectObject(hDC, zero);
                Win32Interop.SIZE          psize  = new Win32Interop.SIZE(Width, Height);
                Win32Interop.POINT         pprSrc = new Win32Interop.POINT(0, 0);
                Win32Interop.POINT         pptDst = new Win32Interop.POINT(Left, Top);
                Win32Interop.BLENDFUNCTION pblend = new Win32Interop.BLENDFUNCTION();
                pblend.BlendOp             = 0;
                pblend.BlendFlags          = 0;
                pblend.SourceConstantAlpha = 255;
                pblend.AlphaFormat         = 1;
                Win32Interop.UpdateLayeredWindow(Handle, dC, ref pptDst, ref psize, hDC, ref pprSrc, 0, ref pblend, 2);
            }
            finally
            {
                Win32Interop.ReleaseDC(IntPtr.Zero, dC);
                if (zero != IntPtr.Zero)
                {
                    Win32Interop.SelectObject(hDC, hObject);
                    Win32Interop.DeleteObject(zero);
                }
                Win32Interop.DeleteDC(hDC);
            }
        }