15 Ocak 2011 Cumartesi

Aero Style Forms

        #region ----- Aero Form

 

        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]

        public struct MARGINS

        {

            public int Left;

            public int Right;

            public int Top;

            public int Bottom;

        }

 

        private MARGINS margins;

        [System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]

        public static extern void DwmExtendFrameIntoClientArea

                        (IntPtr hwnd, ref MARGINS margins);

 

        [System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]

        public static extern bool DwmIsCompositionEnabled();

 

        protected override void OnLoad(EventArgs e)

        {

            base.OnLoad(e);

            if (DwmIsCompositionEnabled())

            {

                // Paint the glass effect.

                margins = new MARGINS();

                margins.Top = 50;

                DwmExtendFrameIntoClientArea(this.Handle, ref margins);

            }

        }

 

        protected override void OnPaintBackground(PaintEventArgs e)

        {

            base.OnPaint(e);

            if (DwmIsCompositionEnabled())

            {

                // paint background black to enable include glass regions

 

                e.Graphics.Clear(Color.Black);

                // revert the non-glass rectangle back to it's original colour

 

                Rectangle clientArea = new Rectangle(

                        margins.Left,

                        margins.Top,

                        this.ClientRectangle.Width - margins.Left - margins.Right,

                        this.ClientRectangle.Height - margins.Top - margins.Bottom

                    );

                Brush b = new SolidBrush(this.BackColor);

                e.Graphics.FillRectangle(b, clientArea);

            }

        }

 

        #endregion

 

Hiç yorum yok:

Yorum Gönderme