效果如下:

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace VistaForm
    {
        public partial class GlassForm : Form
        {
            //private GlassForm vistaForm = null;
            public GlassForm()
            {
                InitializeComponent();
                //FocusForm = this;
                base.Padding = new Padding(7, 24, 7, 7);
                base.Opacity = 0.99;
                this.FormBorderStyle = FormBorderStyle.None;
                SetStyle(ControlStyles.UserPaint, true);
                SetStyle(ControlStyles.AllPaintingInWmPaint, true);
               SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                SetStyle(ControlStyles.SupportsTransparentBackColor, true);
                SetStyle(ControlStyles.ResizeRedraw, true);
            }
            public new double Opacity
            {
                get
                {
                    return 1;
                }
            }
            public new Padding Padding
            {
                get
                {
                    return base.Padding;
                }
            }        private Sayes.Controls.Vista.Config.Color _ColorSetting = new Sayes.Controls.Vista.Config.Color();        private void EnableAllControls()
            {
                if (this==null || this.Controls == null) return;
                foreach (Control ctl in this.Controls) ctl.Enabled = true;
            }
            private void DisableAllControls()
            {
                foreach (Control ctl in this.Controls) ctl.Enabled = false;
            }
            internal Sayes.Controls.Vista.Config.Color ColorSetting
            {
                get { return _ColorSetting; }
            }
            private Region MinRegion = new Region(), MaxRegion = new Region(), CloseRegion = new Region();
            
            private bool IsMinOn = false, IsMaxOn = false, IsCloseOn = false;
            private static GlassForm FocusForm = null;
            protected override void OnDeactivate(EventArgs e)
            {
                base.OnDeactivate(e);
                this.timerBackGround.Start();
                this.DisableAllControls();
            }
            protected override void OnActivated(EventArgs e)
            {
                base.OnActivated(e);            FocusForm = this;
             
                this.timerBackGround.Stop();
                this.Invalidate();
                this.EnableAllControls();
            }
            protected override void OnLocationChanged(EventArgs e)
            {
                base.OnLocationChanged(e);
                this.Invalidate();
            }
      

  2.   

     protected override void OnPaint(PaintEventArgs e)
            { 
                base.OnPaint(e);
                e.Graphics.Clear(System.Drawing.Color.White);
                e.Graphics.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), new Size(this.Width, 30));//顶
                e.Graphics.DrawImage(global::VistaForm.Properties.Resources.hear, 0, 0, this.Width, 30);
                e.Graphics.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), new Size(7, this.Height));//左
                e.Graphics.DrawImage(global::VistaForm.Properties.Resources.wi, 0,30);
               e.Graphics.CopyFromScreen(this.PointToScreen(new Point(this.Width - 7, 0)), new Point(this.Width - 7, 0), new Size(7, this.Height));//右
               e.Graphics.DrawImage(global::VistaForm.Properties.Resources.wi, this.Width - 7, 30);
                e.Graphics.CopyFromScreen(this.PointToScreen(new Point(0, this.Height - 11)), new Point(0, this.Height - 11), new Size(this.Width, 11));//底
                if (FocusForm==this)
                {
                    //e.Graphics.FillRectangle(new SolidBrush(this.ColorSetting.ActiveHeaderColor),
                    //   new Rectangle(new Point(0, 0), this.Size));//设置色.不要时是全透明
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(this.ColorSetting.HeaderColor),
                       new Rectangle(new Point(0, 0), this.Size));
                }
               
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;//.HighQuality;            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
               
                path.AddLine(2, 0, this.Width - 4, 0);
                path.AddLine(this.Width - 4, 0, this.Width - 2, 2);
                path.AddLine(this.Width - 2, 2, this.Width - 2, this.Height - 4);
                path.AddLine(this.Width - 2, this.Height - 4, this.Width - 4, this.Height - 2);
                path.AddLine(this.Width - 4, this.Height - 2, 2, this.Height - 2);
                path.AddLine(2, this.Height - 2, 0, this.Height - 4);
                path.AddLine(0, this.Height - 4, 0, 2);
                path.AddLine(0, 2, 2, 0);
                
                System.Drawing.Drawing2D.GraphicsPath pathFrame = new System.Drawing.Drawing2D.GraphicsPath();
                pathFrame.AddLine(2, 0, this.Width - 3, 0);
                pathFrame.AddLine(this.Width - 3, 0, this.Width - 1, 2);
                pathFrame.AddLine(this.Width - 1, 2, this.Width - 1, this.Height - 3);
                pathFrame.AddLine(this.Width - 1, this.Height - 4, this.Width - 4, this.Height - 1);
                pathFrame.AddLine(this.Width - 4, this.Height - 1, 2, this.Height - 1);
                pathFrame.AddLine(2, this.Height - 1, 0, this.Height - 4);
                pathFrame.AddLine(0, this.Height - 4, 0, 2);
                pathFrame.AddLine(0, 2, 2, 0);
                this.Region = new Region(pathFrame);
                //
                //Pen mypen = new Pen(Color.PaleTurquoise);
                ////Pen mypen = new Pen(Color.White );
                //Graphics myline = this.CreateGraphics();
                //myline.DrawLine(mypen, 2, this.Height - 1, 0, this.Height - 4);
                //            
                this.BackColor = this.ColorSetting.BackColor;
                if (FocusForm == this) e.Graphics.DrawPath(new Pen(this.ColorSetting.ActiveBorderColor), path);
                else e.Graphics.DrawPath(new Pen(this.ColorSetting.BorderColor), path);            Rectangle clientRegion = new Rectangle(6, 28, this.Width - 15, this.Height - 37);//设置边框
                e.Graphics.FillRectangle(new SolidBrush(this.ColorSetting.BackColor), clientRegion);
                if (FocusForm == this)
                    e.Graphics.DrawRectangle(new Pen(this.ColorSetting.ActiveBorderColor), clientRegion);
                else 
                    e.Graphics.DrawRectangle(new Pen(this.ColorSetting.BorderColor), clientRegion);
                if(this.BackgroundImage!=null)
                    e.Graphics.DrawImage(this.BackgroundImage, clientRegion);            if(this.Icon!=null)
                    e.Graphics.DrawIcon(this.Icon, new Rectangle(3, 3, 16, 16));
                Font f = new Font("ArialBlack", (float)9,FontStyle.Bold);
                e.Graphics.DrawString(this.Text, f, Brushes.White, 21, 3);
                e.Graphics.DrawString(this.Text, f, Brushes.White, 23, 3);
                e.Graphics.DrawString(this.Text, f, Brushes.White, 22, 2);
                e.Graphics.DrawString(this.Text, f, Brushes.White, 22, 4);
                e.Graphics.DrawString(this.Text, f, Brushes.Black, 22, 3);            if (this.IsMinOn)
                {
                    e.Graphics.DrawImage(global::VistaForm.Properties.Resources.MinHigh,
                        this.MinRegion.GetBounds(e.Graphics));
                }
                else
                {
                    e.Graphics.DrawImage(global::VistaForm.Properties.Resources.Min,
                        this.MinRegion.GetBounds(e.Graphics));
                }
                if (this.IsCloseOn)
                {
                    e.Graphics.DrawImage(global::VistaForm.Properties.Resources.CloseHigh,
                        this.CloseRegion.GetBounds(e.Graphics));
                }
                else
                {
                    e.Graphics.DrawImage(global::VistaForm.Properties.Resources.Close,
                        this.CloseRegion.GetBounds(e.Graphics));
                }
                if (this.IsMaxOn)
                {
                    e.Graphics.DrawImage(global::VistaForm.Properties.Resources.MaxHigh,
                        this.MaxRegion.GetBounds(e.Graphics));            }
                else
                {
                    e.Graphics.DrawImage(global::VistaForm.Properties.Resources.Max,
                        this.MaxRegion.GetBounds(e.Graphics));
                }
            }
      

  3.   

     protected override void OnResize(EventArgs e)
            {
                base.OnResize(e);
                try
                {
                    this.MinRegion = new Region(new Rectangle(this.Width - 110, 1, 30, 20));//三个按钮位置大小等设置
                    this.MaxRegion = new Region(new Rectangle(this.Width - 79, 1, 30, 20));
                    this.CloseRegion = new Region(new Rectangle(this.Width - 49, 1, 40, 20));
                }
                catch { }
            }
            private Point StartPoint = new Point(0, 0);
            private bool IsMoveClick = false;
            private bool IsClick = false;
            protected override void OnMouseDown(MouseEventArgs e)
            {
                base.OnMouseDown(e);
                this.StartPoint = new Point(e.X, e.Y);            if (e.Y < 23)
                {
                    if (!this.MinRegion.IsVisible(new Point(e.X, e.Y)) && !this.MaxRegion.IsVisible(new Point(e.X, e.Y)) &&
                        !this.CloseRegion.IsVisible(new Point(e.X, e.Y))) this.IsMoveClick = true;
                }
                else this.IsClick = true;
            }
            protected override void OnMouseLeave(EventArgs e)
            {
                base.OnMouseLeave(e);
                this.Cursor = Cursors.Default;
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                base.OnMouseMove(e);
                this.Cursor = Cursors.Default;
                if (this.MinRegion.IsVisible(new Point(e.X, e.Y)) && !this.IsMinOn)
                {
                    this.IsMinOn = true;
                    this.IsMaxOn = false;
                    this.IsCloseOn = false;
                    this.Cursor = Cursors.Hand;
                    this.Invalidate(this.MinRegion);
                    this.Invalidate(this.CloseRegion);
                    this.Invalidate(this.MaxRegion);
                }
                if (this.MaxRegion.IsVisible(new Point(e.X, e.Y)) && !this.IsMaxOn)
                {
                    this.IsMinOn = false;
                    this.IsCloseOn = false;
                    this.IsMaxOn = true;
                    this.Cursor = Cursors.Hand;
                    this.Invalidate(this.MinRegion);
                    this.Invalidate(this.MaxRegion);
                    this.Invalidate(this.CloseRegion);
                }
                if (this.CloseRegion.IsVisible(new Point(e.X, e.Y)) && !this.IsCloseOn)
                {
                    this.IsMinOn = false;
                    this.IsMaxOn = false;
                    this.IsCloseOn = true;
                    this.Cursor = Cursors.Hand;
                    this.Invalidate(this.MinRegion);
                    this.Invalidate(this.CloseRegion);
                    this.Invalidate(this.MaxRegion);
                }            if (this.IsMoveClick)
                {
                    this.Left += e.X - this.StartPoint.X;
                    this.Top += e.Y - this.StartPoint.Y;
                }
                if (e.X > this.Width - 6 && e.Y >= 23 && e.Y <= this.Height - 6)//right
                {
                    this.Cursor = Cursors.SizeWE;
                    if (this.IsClick)
                    {
                        this.Width += e.X - this.StartPoint.X;
                        this.StartPoint = new Point(e.X, e.Y);
                    }
                }
                else if (e.X > this.Width - 6 && e.Y > this.Height - 6)//right bottom corner
                {
                    this.Cursor = Cursors.SizeNWSE;
                    if (this.IsClick)
                    {
                        this.Width += e.X - this.StartPoint.X;
                        this.Height += e.Y - this.StartPoint.Y;
                        this.StartPoint = new Point(e.X, e.Y);
                    }
                }
                else if (e.Y > this.Height - 6)//bottom
                {
                    this.Cursor = Cursors.SizeNS;
                    if (this.IsClick)
                    {
                        this.Height -= this.StartPoint.Y - e.Y;
                        this.StartPoint = new Point(e.X, e.Y);
                    }
                }//
                
                
                //
                else
                {
                    this.Cursor = Cursors.Default;            }
            }
            protected override void OnMouseUp(MouseEventArgs e)
            {
                base.OnMouseUp(e);
                if (this.MinRegion.IsVisible(new Point(e.X, e.Y)) && this.MinimizeBox)
                {
                 
                    this.WindowState = FormWindowState.Minimized;
                }
                if (this.MaxRegion.IsVisible(new Point(e.X, e.Y)) && this.MaximizeBox)
                {
                    if (this.WindowState == FormWindowState.Normal)
                    {
                        this.WindowState = FormWindowState.Maximized;//取大化
                       
                     
                       
                    }
                    else
                    {
                        this.WindowState = FormWindowState.Normal;
                       
                    }
                    
                }
                if (this.CloseRegion.IsVisible(new Point(e.X, e.Y)))
                {
                    this.Close();
                }
                this.IsClick = false;
                this.IsMoveClick = false;
                this.StartPoint = new Point(0, 0);
            }
      

  4.   

    protected override void OnControlAdded(ControlEventArgs e)
            {
                base.OnControlRemoved(e);
                e.Control.LocationChanged += new EventHandler(Control_SizeChanged);
                e.Control.SizeChanged += new EventHandler(Control_SizeChanged);
                this.Control_SizeChanged(e.Control, null);
            }        void Control_SizeChanged(object sender, EventArgs e)
            {
                Control ctl = (Control)sender;
                if (ctl.Dock != DockStyle.None) return;
                if (ctl.Width > this.Width - 8) ctl.Width = this.Width - 8;
                if (ctl.Height > this.Height - 8) ctl.Height = this.Height - 8;
                if (ctl.Left < 3) ctl.Left = 4;
                if (ctl.Right > this.Width - 3) ctl.Left = this.Width - 4 - ctl.Width;
                if (ctl.Top < 23) ctl.Top = 24;
                if (ctl.Bottom > this.Height - 3) ctl.Top = this.Height - 4 - ctl.Height;
            }        private void timerBackGround_Tick(object sender, EventArgs e)
            {
                if(this!=FocusForm)this.Invalidate(false);
            }    }
    }
      

  5.   

    太長了,發不了,能不能打個包發給我呀,多謝了 [email protected]
      

  6.   

    太好了,谢谢楼主,能不能打包发给我,十分感谢! [email protected]
      

  7.   

    让大家有更多的参考:楼主不介意吧?等我有时间,我会进一步完善的。最近也有了一些新的心得,拭目以待吧。
    http://hi.baidu.com/tease/blog/item/ac608554be72a31b3b2935eb.html
    还有,Vista的毛玻璃效果似乎使用了多种模糊特效,在我的这篇文章中,仅仅只使用了“高斯模糊”,我不太清楚如何去更好的模拟毛玻璃特效(实际上我对图像处理并不专业),不知道楼主有没有什么好的思路?
      

  8.   

    以上均为核心代码!这么多人要发也发不完.你们可以参考我的代码.
    cici
    你好,我看了一些高期糊模的算法.C#的很少,也不好.我用potoshop试过了.就是用一个高斯模糊就搞定了.所以我看近期不打算再放高斯模糊的版本.期实不一定要做到和vista一样的效果,但我要做到比vista更好!
    各位有更好的方法请留言!!!
      

  9.   

    你好能发给我一份完整的代码吗?急需学习。[email protected]。谢谢
      

  10.   

    楼主你太棒了,打包发一份给好吗,学习学习,邮件:[email protected]
      

  11.   

    楼主强呀,很早都想要这效果,但是我不会PS,呵呵,希望要分源码,能不能发份给我谢谢:[email protected]
      

  12.   

    我也想要,麻烦楼主了~~学习学习[email protected]
      

  13.   

    给我一份吧[email protected]  谢谢
      

  14.   

    正在学习GUI 给我一份吧 [email protected]
      

  15.   

    给一份我呗。谢谢楼主了。
    [email protected]
    谢谢啦,好心人。
      

  16.   

    楼主 可以把源代码发一份不 谢谢[email protected]
      

  17.   

    樓主 我也想要一份![email protected] 太感謝了!