C#轻松打造vista透明窗口(xp系统无任何vista主题)(汤贞营作品)

news/2023/11/29 5:17:53

 

自vista出来之后,.vista的areo透明效果取得了消费者的好评.因此vista的areo特效成为了程序员青睐的一种特效.

但要在vista系统上才能运行透明窗体.但这就说明在XP系统就不能实现areo了吗?

回答是否定的.在xp早期的版本下一样可以运行areo透明特效!

哈,不信你可要看清楚了!!!!!!如下图::

是的.认真看它不是vista系统下的窗口.哈比vista的还先进!!

源代码好长.只给出核心代码!!!

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();
        }
     
        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));
            }
        }
        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);
        }

        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);
        }

    }
}


http://www.ppmy.cn/news/652469.html

相关文章

Windows 2008 如何开启并使用Windows Vista的主题

据说 Windows Server 2008中使用Vista相同的核心。 默认情况下&#xff0c;Windows Server 2008的界面是比较单调的&#xff0c;这是因为作为服务器操作系统&#xff0c;Windows Server 2008默认并没有启用主题服务和Vista界面&#xff0c;所以今天就教大家如何在Windows Serve…

在主线程中为子线程解锁_在XP中为Google Chrome启用Vista黑色风格主题

在主线程中为子线程解锁 If you’ve seen the screenshots of Google Chrome on XP vs Vista, you’ve probably noticed that the interface looks completely different. If you want to make your XP version use a slick black theme, you can do so with a custom hack. 如…

W2k8应用vista主题

简单的将vista主题应用到2008系统 系统自带 下面以图说话 1&#xff09;打开服务器管理器----->角色------>添加角色------桌面体验 2&#xff09;安装时会提示重启 &#xff0c;重启进入系统后 打开服务 将Theme主题服务启动 3&#xff09;鼠标在桌面右击 -->个性…

Windows Server 2008 如何实现Vista主题

Windows Server 2008操作系统有很多功能在默认情况下是没有安装的&#xff0c;这就需要用户在系统安装成功后手动安装添加的。桌面主题就是其中一个功能&#xff0c;下面简单介绍一下桌面主题的安装方法&#xff1a; 1、打开【服务器管理器】 2、选择【功能】&#xff0c;在右…

怨念主题第2作~粉红色超级女人vista主题

下载地址&#xff1a;234jo02pinkvista.rar 今天怨念大爆发&#xff0c;突然间想要做一个超级女人风的主题。。。。 没事干时候翻翻电脑&#xff0c;发现俺自己真的实在是太男人了。 朋友过来拷软件&#xff0c;我给她推荐一些好看的主题&#xff0c;结果她默了很久 然后小心…

美化windows 完美仿真Vista -- Vista风格包4.0

http://count.crsky.com/view_down.asp?down_urlhttp://2.gddx1.crsky.com/200611/VistaShow-v4.0.rar&downd_id14&ID30805&SOFTID9036&downyes

Vista主题包(高仿真)_方舟系统站

Vista主题包&#xff08;高仿真&#xff09;_方舟系统站 第四步&#xff0c;外观主题美化&#xff1a;外观主题美化目录里的MV5505目录是VS主题外观文件&#xff0c;目前在 ... 然后在桌面上用右键顺序点击桌面-显示属性-外观-窗口和按钮-中选择这个MV5505 ...

火狐强制刷新_强制Firefox 3在Windows XP中使用Vista默认主题

火狐强制刷新 This article was written by Leon Steadman, the same helpful reader that showed us how to Use a Custom Theme for the XP Classic Logon Screen. 本文由Leon Steadman撰写&#xff0c;Leon Steadman是向我们展示如何对 XP Classic Logon Screen使用自定义主…

XP下的VISTA主题及工具完全包!

Vista主题完美风格包V5.1 本风格包只适用XPsp2&#xff0c;未装过美化包和美化软件的系统&#xff0c;否则请不要使用。风格包已集成各类优秀美化效果。5、本风格包不含任何流氓软件和垃圾插件&#xff0c;风格包资源用卡巴6和诺顿2006、12月病毒库打描未发现病毒&#xff0c;请…

如何修补Windows Vista以启用自定义主题(视觉样式)

Have you ever wondered why Windows Vista allows you to choose themes, but there’s no way to add custom themes without additional software? The reason is because Windows checks the themes with a cryptographic key, so you have to patch windows to allow cus…

使用vue+element开发一个谷歌浏览器插件

谷歌浏览器插件-二维码生成器 使用vue2element ui开发&#xff0c;参考文章&#xff1a; https://blog.csdn.net/qq_35606400/article/details/123183420 代码地址&#xff1a;https://github.com/changwenxia/chrome-qr-tools 开发过程&#xff1a; 1.将package.json里的mai…

《深入浅出SSD:固态存储核心技术、原理与实战》----学习记录(二)

第2章 SSD主控和全闪存阵列 SSD主要由两大模块构成——主控和闪存介质。其实除了上述两大模块外&#xff0c;可选的还有缓存单元。主控是SSD的大脑&#xff0c;承担着指挥、运算和协调的作用&#xff0c;具体表现在&#xff1a;一是实现标准主机接口与主机通信&#xff1b;二…

苹果6s上市时间_iPhone7的A10处理器还能战多长时间?2-3年不成问题!

iPhone 7采用A10 Fusion处理器&#xff0c;简称A10处理器&#xff0c;在2018年依然是处于高端处理器&#xff0c;再加上苹果自己的系统优化和资源调度&#xff0c;流畅度甚至超过其他安卓835机子。16年上市的iPhone7的A10还能再战多长时间&#xff1f;小编今天来分析一下。 A10…

小马哥--高仿苹果6s 主板型号m718 2017新版机型刷机 拆机主板图与开机图 兼容低日期版本

这款山寨机型日期版本很多 正常新日期版本的兼容旧日期版本机型 这款机型更换屏幕型号很多 201611月以后出厂的机型都更换了新型号屏幕硬件 刷旧版的开机花屏或者黑屏 另外 新版的机型调整了内核 必须刷新版内核 摄像头这些才可以正常使用 实测以下版本 上图

小马哥--高仿苹果6S 主板型号E127 6572芯片刷机开机界面图与识别图 新版机型

高仿苹果版本e127 遇到的机型有苹果6 和这款最新的苹果6s 属于低配版本 采用nand字库 6572芯片 目前这个版本最新的是20151110的版本 新版 刷机警惕 上图

快易苹果恢复软件

快易苹果恢复软件是一款功能强大&#xff0c;且十分专业的苹果手机数据恢复软件&#xff0c;可助轻松恢复iPhone、iPad、iPod touch等手机内的通讯录、照片、书签、视频、日历、备忘录、视频、照片、注意、提醒、语音、文件等诸多数据&#xff0c;并且&#xff0c;软件还有着简…

vue 中node-sass和sass版本问题解决

先开始使用 “node-sass”: “^7.0.1” “sass-loader”: “^10.0.5” 然后使用npm install报错 后面百度&#xff0c;搜到了是因为 node-sass和sass-loader版本不对应造成。 然后修改版本&#xff0c;增加sass引用 “node-sass”: “^7.0.1” “sass-loader”: “^7.3.1”, “…

苹果系统版本依次顺序_iphone所有型号上市顺序

Ready 本期给大家讲讲iphone所有型号上市顺序。 第一代iPhone于2007年1月9日由苹果公司前首席执行官史蒂夫乔布斯发布&#xff0c;并在2007年6月29日正式发售。 第二代iPhone 3G于2008年6月10日由美国苹果公司的掌门人史蒂夫乔布斯在苹果全球开发者大会上正式发布。 第三代iPho…

有一个苹果6S的兼容性问题

2019独角兽企业重金招聘Python工程师标准>>> 之前做项目的时候&#xff0c;有一个页面有个短信验证&#xff0c;需要输入验证码&#xff0c;然后验证&#xff0c;但是在苹果6s手机上面&#xff0c;点击输入验证码框的时候&#xff0c;居然触发了页面刷新&#xff0c…

php 获取苹果手机型号,iOS获取设备型号(含iPhone12)

(NSString *)getDeviceIdentifier { // 需要#import "sys/utsname.h" struct utsname systemInfo; uname(&systemInfo); // 获取设备标识Identifier NSString *platform [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; // iP…
最新文章