Пример #1
0
        public void DwmEnableBlurBehindWindowTest()
        {
            var wnd = new Form {
                Size = new Size(50, 50), TopMost = true, ControlBox = false, FormBorderStyle = FormBorderStyle.None
            };

            wnd.Show();
            Thread.Sleep(1000);
            var bb  = new DWM_BLURBEHIND(true);
            var err = DwmEnableBlurBehindWindow(wnd.Handle, ref bb);

            Assert.That(err.Succeeded);
            Thread.Sleep(1000);
            using (var g = wnd.CreateGraphics())
            {
                bb.SetRegion(g, new Region(new Rectangle(0, 0, 20, 20)));
                err = DwmEnableBlurBehindWindow(wnd.Handle, ref bb);
                Assert.That(err.Succeeded);
                Thread.Sleep(1000);
            }
            var bb2 = new DWM_BLURBEHIND(false);

            err = DwmEnableBlurBehindWindow(wnd.Handle, ref bb2);
            Assert.That(err.Succeeded);
            Thread.Sleep(1000);
            wnd.Hide();
        }
Пример #2
0
        /// <summary>
        /// Enable the Aero "Blur Behind" effect on a specific region of a drawing area. Background must be black.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="graphics">The graphics area on which the region resides.</param>
        /// <param name="region">The region within the client area to apply the blur behind.</param>
        /// <param name="enabled"><c>true</c> to enable blur behind for this region, <c>false</c> to disable it.</param>
        /// <param name="transitionOnMaximized"><c>true</c> if the window's colorization should transition to match the maximized windows; otherwise, <c>false</c>.</param>
        public static void EnableBlurBehind(this IWin32Window window, Graphics graphics, Region region, bool enabled, bool transitionOnMaximized)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }
            var bb = new DWM_BLURBEHIND(enabled);

            if (graphics != null && region != null)
            {
                bb.SetRegion(graphics, region);
            }
            if (transitionOnMaximized)
            {
                bb.TransitionOnMaximized = true;
            }
            DwmEnableBlurBehindWindow(window.Handle, ref bb);
        }