C#轻松打造vista透明窗口(xp系统无任何vista主题)(汤贞营作品)
自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);
}
}
}
C#轻松打造vista透明窗口(xp系统无任何vista主题)(汤贞营作品)相关推荐
- 小程序商城制作,轻松打造自己的会员系统
2019独角兽企业重金招聘Python工程师标准>>> 小程序商城制作,轻松打造自己的会员系统 详情了解:http://www.jnqianle.cn/mall/ 简约版页面截图 : ...
- 打造口袋版XP系统—— WIN PE系统U盘版
目前网上流传的U盘版Windows PE系统有很多,都是在简化版的Windows 98/ME/XP基础之上再添加第三方系统维护工具制作出来的,它们之间的区别主要就是集成的第三方工具不同,集成的第三方工 ...
- 打造口袋版XP系统—— WIN PE系统U盘版(可上网)
目前网上流传的U盘版Windows PE系统有很多,都是在简化版的Windows 98/ME/XP基础之上再添加第三方系统维护工具制作出来的,它们之间的区别主要就是集成的第三方工具不同,集成的第三方工 ...
- xp系统无打印机服务器,WinXP局域网共享及网络打印机无任何网络提供程序怎么办?...
我们在WinXP 系统上配置局域网和设置打印机的时候,会遇到无任何网络提供程序接受指定的网络路径.明明网络可以上网,怎么会出现无任何网络提供程序的呢?怎么办?遇到这样的情况,我们应该如何去处理它呢?下 ...
- 打造最小的XP系统180M
一直想弄清楚XP系统内核到底有多大,这几天比较闲,就开始动手了. 180M,是最小了,没办法再小了,还有谁能将它减的更小,我们讨论讨论. 内核中包含了:多媒体(DX).数据库.网络.后面两个容易删掉, ...
- 【rmzt】XP系统动漫桌面主题下载
Q版可爱火影忍者主题 系统:Win2003,WinXP 大小:2.17 MB 仙剑情缘3动漫主题 系统:Win2003,WinXP 大小:2.04 MB 红枫林中的女孩动漫主题 系统:Win2003, ...
- Windows 10可三步重回经典XP系统外观 免安装主题
还怀念Windows XP吗?历史车轮滚滚向前,发布近两年的Windows 10已经占据了全球1/4的操作系统市场,XP作为曾经的经典也难逃被弃的命运.不过,如果你是怀旧党,不妨尝试大神TurrboS ...
- 如何一键设置Win8/Win7/Vista/XP系统默认字体
很多时候,大家看到别人的电脑总是感觉很个性,那种与众不同总是让我们自己内心爆发一种强烈的欲望,我们也是独特的.于是乎,各种第三方主题包.图标.鼠标指针--接踵而来,更是有酷点桌面等类似桌面工具,把自己 ...
- windows xp 超级模仿windows Vista全攻略 一模一样的感觉
windows xp 超级模仿windows Vista全攻略 一模一样的感觉 前不久,微软发布了其最新版操作系统Windows Vista.相比以前版本,新系统在很多方面都进行了大幅度改进.但要说最 ...
最新文章
- Python调整图片大小并保存调整后的图像
- 【EventBus】EventBus 源码解析 ( 注册订阅者 | 订阅方法 | 查找订阅方法 )
- ubuntu配置android开发环境和编译源码遇到的一些问题
- 计算机文化基础教程问什么好难买到,问一个翻译的问题新编计算机文化基础(教程 – 手机爱问...
- php txt,PHP规范TXT文件
- 力扣- -阶乘函数后K个零
- leetcode 554. 砖墙
- 阿里云服务器一分价钱一分货,切记!
- Machine learning for improved image-based wavefront sensing
- 学习Spring(一) -- 配置Spring
- ML/DL-复习笔记【二】- L1正则化和L2正则化
- Introduction to Computer Networking学习笔记(十一):flow control 滑动窗口详解
- javamail课设_JavaMail简易教程
- LTE核心网中,SGW、PGW、PCRF都有计费的功能,请问这几个网元的计费功能有什么区别与联系呢?...
- 1449异常 mysql_mysql异常-UncategorizedSQLException 1449
- c++的cout输出
- 远程审批、远程会议及远程培训就用天翼云办公
- 高等数值计算方法学习笔记第4章第一部分【数值积分(数值微分)】
- 【Windows 10 驱动程序 已解决】重装 Win 10 系统后 电脑无法识别外接屏幕。投影:你的电脑不能投影到其他屏幕。请尝试重新安装驱动程序或使用其他视频卡。
- ctex安装及使用技巧