Esempio n. 1
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);
        }
Esempio n. 2
0
        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;
            }
        }