コード例 #1
0
        /// <summary>
        /// Excludes the specified child control from the glass effect.
        /// </summary>
        /// <param name="parent">The parent control.</param>
        /// <param name="control">The control to exclude.</param>
        /// <exception cref="ArgumentNullException">Occurs if control is null.</exception>
        /// <exception cref="ArgumentException">Occurs if control is not a child control.</exception>
        public static void ExcludeChildFromGlass(this Control parent, Control control)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }
            if (!parent.Contains(control))
            {
                throw new ArgumentException("Control must be a child control.");
            }

            if (IsCompositionEnabled())
            {
                System.Drawing.Rectangle clientScreen  = parent.RectangleToScreen(parent.ClientRectangle);
                System.Drawing.Rectangle controlScreen = control.RectangleToScreen(control.ClientRectangle);

                NativeMethods.Margins margins = new NativeMethods.Margins(controlScreen.Left - clientScreen.Left, controlScreen.Top - clientScreen.Top,
                                                                          clientScreen.Right - controlScreen.Right, clientScreen.Bottom - controlScreen.Bottom);

                // Extend the Frame into client area
                NativeMethods.DwmExtendFrameIntoClientArea(parent.Handle, ref margins);
            }
        }
コード例 #2
0
            public void Set(IntPtr window, bool enabled)
            {
                if (!NativeMethods.DwmIsCompositionEnabled())
                {
                    return;
                }

                if (enabled)
                {
                    HwndSource.FromHwnd(window)?.AddHook(WndProc);
                }
                else
                {
                    HwndSource.FromHwnd(window)?.RemoveHook(WndProc);
                }

                var margins = new NativeMethods.Margins {
                    Left = -1, Right = -1, Bottom = -1, Top = -1
                };
                var blurBehind = new NativeMethods.DwmBlurBehind {
                    Enable = enabled, Flags = NativeMethods.DwmFlags.BlurBackground
                };

                NativeMethods.DwmExtendFrameIntoClientArea(window, ref margins);
                NativeMethods.DwmEnableBlurBehindWindow(window, ref blurBehind);
            }
コード例 #3
0
 /// <summary>
 /// Extends the window frame beyond the client area.
 /// </summary>
 /// <param name="window">The window.</param>
 /// <param name="padding">The padding to use as the area into which the frame is extended.</param>
 public static void ExtendFrameIntoClientArea(this IWin32Window window, Padding padding)
 {
     if (window == null)
     {
         throw new ArgumentNullException(nameof(window));
     }
     NativeMethods.Margins m = new NativeMethods.Margins(padding);
     NativeMethods.DwmExtendFrameIntoClientArea(window.Handle, ref m);
 }
コード例 #4
0
 /// <summary>
 /// Extends the window frame beyond the client area.
 /// </summary>
 /// <param name="window">The window.</param>
 /// <param name="padding">The padding to use as the area into which the frame is extended.</param>
 public static void ExtendFrameIntoClientArea(this IWin32Window window, Padding padding)
 {
     NativeMethods.Margins m = new NativeMethods.Margins(padding);
     NativeMethods.DwmExtendFrameIntoClientArea(window.Handle, ref m);
 }