Example #1
0
        public static bool IsGlassEnabled()//Check if glass is enabled on the system
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                return(false);
            }
            bool isGlassSupported = false;

            GlassApi.DwmIsCompositionEnabled(ref isGlassSupported);
            return(isGlassSupported);
        }
Example #2
0
        //initialize the glass areas of the form
        public void extendFrame(int Top, int Bottom, int Left, int Right, Form thisForm)
        {
            if (!GlassApi.IsGlassEnabled())
            {
                return;
            }

            //set glass margins
            Margins margins;

            margins.Top    = Top;
            margins.Bottom = Bottom;
            margins.Left   = Left;
            margins.Right  = Right;

            Form f = new Form();

            f = thisForm;
            f.TransparencyKey = transColor;
            GlassApi.DwmExtendFrameIntoClientArea(f.Handle, ref margins);
        }
        public void extendFrame(int top, int bottom, int left, int right, Window window)
        {
            try
            {
                //set the form background to transparent
                window.Background = Brushes.Transparent;
                // Get the window handle
                IntPtr     mainWindowPtr = new WindowInteropHelper(window).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                // Get the system dpi values
                System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
                float DpiX  = desktop.DpiX;
                float pDpiY = desktop.DpiY;

                // Set Margins
                Margins margins = new Margins();

                margins.Left   = Convert.ToInt32((left + 5) * (DpiX / 96));
                margins.Right  = Convert.ToInt32((right + 5) * (DpiX / 96));
                margins.Top    = Convert.ToInt32((top + 5) * (DpiX / 96));
                margins.Bottom = Convert.ToInt32((bottom + 5) * (DpiX / 96));

                int check = GlassApi.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);

                if (check < 0)
                {
                    //Cannot extend frame so set background to default
                    window.Background = defaultColor;
                }
            }
            // If aero is not supported paint the background default
            catch (DllNotFoundException)
            {
                window.Background = defaultColor;
            }
        }
Example #4
0
        private void GlassPane_Load(object sender, EventArgs e)
        {
            if (GlassApi.IsGlassEnabled())
            {
                this.BackColor = transColor;
            }
            else
            {
                this.BackColor = defaultColor;
            }

            if (autoExt)
            {
                //if the form is docked,automatically initialize glass
                if (this.Dock == DockStyle.Bottom)
                {
                    g.extendFrame(0, this.Height, 0, 0, this.ParentForm);
                }
                else if (this.Dock == DockStyle.Top)
                {
                    g.extendFrame(this.Height, 0, 0, 0, this.ParentForm);
                }
                else if (this.Dock == DockStyle.Left)
                {
                    g.extendFrame(0, 0, this.Width, 0, this.ParentForm);
                }
                else if (this.Dock == DockStyle.Right)
                {
                    g.extendFrame(0, 0, 0, this.Width, this.ParentForm);
                }
                else if (this.Dock == DockStyle.Fill)
                {
                    g.extendFrame(this.ParentForm);
                }
            }
        }