开始写这一系列博客之前先要向大家说声抱歉,放肆雷特建立很久却很少有更新。当然博客人气也不旺,大部分都是看的人多评论收藏的人少。一直想要改变这种状态,正好赶上了最近工作上做了一个高仿360安全卫士窗体。所以将开发历程分享出来,一来希望能和大家交流共同学习成长;二来希望自己的放肆雷特能有人光顾。

这一系列的文章所用到的技术首先要感谢苏飞大哥,我也是在很早以前看了他的QQ皮肤制作文章之后得到的灵感和一些相关知识。在这里帮他的C#论坛打个广告,里面有不少比较有用的资料。苏飞大哥也是很用心的打理这个论坛,论坛地址http://www.sufeinet.com/

说了这么多也该进入主题了,首先为了让大家有兴趣看下去而且认同我开发的这个皮肤,所以先传上本程序的界面截图(不喜勿喷)。同时本人也先声明,本人属屌丝一枚,想法和思路可能比较落后,如果你有比较不错的想法和思路可以在本论坛中寻找本人qq或评论本文。

第一章:360安全卫士窗体素材提取

360安全卫士的窗体使用的素材比之前QQ的素材更容易提取首先安装360安全卫士,如果怕自己电脑中毒的请使用虚拟机进行安装。在这里不提供下载链接。安装好之后打开安装目录,我这里以安装到C盘为准:
C:\Program Files (x86)\360\360safe\Config\newui\themes\default
打开后,将default_theme.ui文件拷贝出来。再将它的后缀改名为rar。之后的操作你懂的呀。。操作之后得到

第二章:360安全卫士风格按钮开发
得到以上素材之后开始正式的编码,第一个要开发的控件是Button控件,为什么呢?因为窗体上的关闭、最大化、最小化这些按钮都可以使用。系统里面用到的WinApi类我就不放上来了,网上一搜一大把,如果有需要的可以单独向我索取。写按钮前,先枚举该按钮的所有状态,我这里定义5个状态,应该比较全了:

 /// <summary>
/// 枚举按钮状态
/// </summary>
public enum State
{
Normal = ,//按钮默认时
MouseOver = ,//鼠标移上按钮时
MouseDown = ,//鼠标按下按钮时
Disable = ,//当不启用按钮时(也就是按钮属性Enabled==Ture时)
Default = //控件得到Tab焦点时
}

重绘按钮以及重绘其它控件及窗体用到的方法:
1、该方法是将素材切割后再进行绘制,这样在按钮大小发生改变时也不会对素材的大小有影响:

 /// <summary>
/// 绘图对像
/// </summary>
/// <param name="g">绘图对像</param>
/// <param name="img">图片</param>
/// <param name="r">绘置的图片大小、坐标</param>
/// <param name="lr">绘置的图片边界</param>
/// <param name="index">当前状态</param>
/// <param name="Totalindex">状态总数</param>
public static void DrawRect(Graphics g, Bitmap img, Rectangle r, Rectangle lr, int index, int Totalindex)
{
if (img == null) return;
Rectangle r1, r2;
int x = (index - ) * img.Width / Totalindex;
int y = ;
int x1 = r.Left;
int y1 = r.Top; if (r.Height > img.Height && r.Width <= img.Width / Totalindex)
{
r1 = new Rectangle(x, y, img.Width / Totalindex, lr.Top);
r2 = new Rectangle(x1, y1, r.Width, lr.Top);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); r1 = new Rectangle(x, y + lr.Top, img.Width / Totalindex, img.Height - lr.Top - lr.Bottom);
r2 = new Rectangle(x1, y1 + lr.Top, r.Width, r.Height - lr.Top - lr.Bottom);
if ((lr.Top + lr.Bottom) == ) r1.Height = r1.Height - ;
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); r1 = new Rectangle(x, y + img.Height - lr.Bottom, img.Width / Totalindex, lr.Bottom);
r2 = new Rectangle(x1, y1 + r.Height - lr.Bottom, r.Width, lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
}
else
if (r.Height <= img.Height && r.Width > img.Width / Totalindex)
{
r1 = new Rectangle(x, y, lr.Left, img.Height);
r2 = new Rectangle(x1, y1, lr.Left, r.Height);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
r1 = new Rectangle(x + lr.Left, y, img.Width / Totalindex - lr.Left - lr.Right, img.Height);
r2 = new Rectangle(x1 + lr.Left, y1, r.Width - lr.Left - lr.Right, r.Height);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y, lr.Right, img.Height);
r2 = new Rectangle(x1 + r.Width - lr.Right, y1, lr.Right, r.Height);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
}
else
if (r.Height <= img.Height && r.Width <= img.Width / Totalindex) { r1 = new Rectangle((index - ) * img.Width / Totalindex, , img.Width / Totalindex, img.Height); g.DrawImage(img, new Rectangle(x1, y1, r.Width, r.Height), r1, GraphicsUnit.Pixel); } else if (r.Height > img.Height && r.Width > img.Width / Totalindex)
{
//top-left
r1 = new Rectangle(x, y, lr.Left, lr.Top);
r2 = new Rectangle(x1, y1, lr.Left, lr.Top);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //top-bottom
r1 = new Rectangle(x, y + img.Height - lr.Bottom, lr.Left, lr.Bottom);
r2 = new Rectangle(x1, y1 + r.Height - lr.Bottom, lr.Left, lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //left
r1 = new Rectangle(x, y + lr.Top, lr.Left, img.Height - lr.Top - lr.Bottom);
r2 = new Rectangle(x1, y1 + lr.Top, lr.Left, r.Height - lr.Top - lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //top
r1 = new Rectangle(x + lr.Left, y,
img.Width / Totalindex - lr.Left - lr.Right, lr.Top);
r2 = new Rectangle(x1 + lr.Left, y1,
r.Width - lr.Left - lr.Right, lr.Top);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //right-top
r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y, lr.Right, lr.Top);
r2 = new Rectangle(x1 + r.Width - lr.Right, y1, lr.Right, lr.Top);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //Right
r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y + lr.Top,
lr.Right, img.Height - lr.Top - lr.Bottom);
r2 = new Rectangle(x1 + r.Width - lr.Right, y1 + lr.Top,
lr.Right, r.Height - lr.Top - lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //right-bottom
r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y + img.Height - lr.Bottom,
lr.Right, lr.Bottom);
r2 = new Rectangle(x1 + r.Width - lr.Right, y1 + r.Height - lr.Bottom,
lr.Right, lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //bottom
r1 = new Rectangle(x + lr.Left, y + img.Height - lr.Bottom,
img.Width / Totalindex - lr.Left - lr.Right, lr.Bottom);
r2 = new Rectangle(x1 + lr.Left, y1 + r.Height - lr.Bottom,
r.Width - lr.Left - lr.Right, lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel); //Center
r1 = new Rectangle(x + lr.Left, y + lr.Top,
img.Width / Totalindex - lr.Left - lr.Right, img.Height - lr.Top - lr.Bottom);
r2 = new Rectangle(x1 + lr.Left, y1 + lr.Top,
r.Width - lr.Left - lr.Right, r.Height - lr.Top - lr.Bottom);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
}
} /// <summary>
/// 绘图对像
/// </summary>
/// <param name="g"> 绘图对像</param>
/// <param name="obj">图片对像</param>
/// <param name="r">绘置的图片大小、坐标</param>
/// <param name="index">当前状态</param>
/// <param name="Totalindex">状态总数</param>
public static void DrawRect(Graphics g, Bitmap img, Rectangle r, int index, int Totalindex)
{
if (img == null) return;
int width = img.Width / Totalindex;
int height = img.Height;
Rectangle r1, r2;
int x = (index - ) * width;
int y = ;
r1 = new Rectangle(x, y, width, height);
r2 = new Rectangle(r.Left, r.Top, r.Width, r.Height);
g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
}

2、该方法是将编译好的图片读取出来

 /// <summary>
/// 得到要绘置的图片对像
/// </summary>
/// <param name="str">图像在程序集中的地址</param>
/// <returns></returns>
public static Bitmap GetResBitmap(string str)
{
Stream sm;
sm = FindStream(str);
if (sm == null) return null;
return new Bitmap(sm);
} /// <summary>
/// 得到图程序集中的图片对像
/// </summary>
/// <param name="str">图像在程序集中的地址</param>
/// <returns></returns>
private static Stream FindStream(string str)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string[] resNames = assembly.GetManifestResourceNames();
foreach (string s in resNames)
{
if (s == str)
{
return assembly.GetManifestResourceStream(s);
}
}
return null;
}

Ok,基础打好之后就可以开始正式的进行按钮绘制,代码比较长,里面包括定义变量,定义按钮属性,处理按钮构造函数。这里我分享关键部分重写OnPaint代码:

 /// <summary>
/// 重绘控件
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (BackImg == null)
{
base.OnPaint(e);
return;
} int i = (int)state;
if (this.Focused && state != State.MouseDown && _IsTabFocus == true) i = ;
if (!this.Enabled) i = ;
Rectangle rc = this.ClientRectangle;
Graphics g = e.Graphics; base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle));
try
{
if (BackImg != null)
{
if (_BacklightLTRB != Rectangle.Empty)
{ ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), i, );
}
else
{
ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(, , , ), i, );
} }
}
catch
{ } Image img = null;
Size txts, imgs; txts = Size.Empty;
imgs = Size.Empty; if (this.Image != null)
{
img = this.Image;
}
else if (this.ImageList != null && this.ImageIndex != -)
{
img = this.ImageList.Images[this.ImageIndex];
} if (img != null)
{
imgs.Width = img.Width;
imgs.Height = img.Height;
} StringFormat format1;
using (format1 = new StringFormat())
{
format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
SizeF ef1 = g.MeasureString(this.Text, this.Font, new SizeF((float)rc.Width, (float)rc.Height), format1);
txts = Size.Ceiling(ef1);
} rc.Inflate(-, -);
if (imgs.Width * imgs.Height != )
{
Rectangle imgr = rc;
imgr = ImageDrawRect.HAlignWithin(imgs, imgr, this.ImageAlign);
imgr = ImageDrawRect.VAlignWithin(imgs, imgr, this.ImageAlign);
if (!this.Enabled)
{
ControlPaint.DrawImageDisabled(g, img, imgr.Left, imgr.Top, this.BackColor);
}
else
{
g.DrawImage(img, imgr.Left, imgr.Top, img.Width, img.Height);
}
} Rectangle txtr = rc;
txtr = ImageDrawRect.HAlignWithin(txts, txtr, this.TextAlign);
txtr = ImageDrawRect.VAlignWithin(txts, txtr, this.TextAlign); format1 = new StringFormat();
format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; if (this.RightToLeft == RightToLeft.Yes)
{
format1.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
}
brush = new SolidBrush(this.ForeColor);
g.DrawString(this.Text, this.Font, brush, (RectangleF)txtr, format1);
brush.Dispose(); }

其中关键部分已经出来,按钮也基本绘制完成。下一篇我将分享重绘主窗体,其中过程也没有详细讲解,主要原因是文采不好。如果有不了解的可以留言给我,我会及时回复。该皮肤的源码由于项目上正在使用暂时不进行公布,如果本文的反响和关注度都不错,我再决定是否提供下载。最后谢谢大家的关注。请期待下一篇的重绘主窗体。


本文来自 放肆雷特 | 胖子的技术博客

C#制作高仿360安全卫士窗体<一>的更多相关文章

  1. C#制作高仿360安全卫士窗体<二>

    继上次C#制作高仿360安全卫士窗体<一>发布之后响应还不错,我的博客放肆雷特也来了不少的新朋友,在这里先谢谢大家的支持!我自己也反复看了一下觉得对不起大家,写的非常乱而且很少文字介绍.在 ...

  2. C#制作高仿360安全卫士窗体(四)- 水晶按钮

    项目越来越紧,我也乐此不疲.自从上次C#制作高仿360安全卫士窗体(三)出来之后,就开始有一些人在说为什么还在坚持写这么落后的东西.我想说的是,我是从事企业信息化工作的,所有程序都只对内部使用.所以只 ...

  3. C#制作高仿360安全卫士窗体(三)

    距上篇C#制作高仿360安全卫士窗体(二)也将近一个多月了,这个月事情还是像往常一样的多.不多我也乐在其中,毕竟我做的是我喜欢做的东西.今天特地抽空把怎么制作文本框写一下.同时也希望有爱好这些玩意的同 ...

  4. C#制作高仿360安全卫士窗体3

    C#制作高仿360安全卫士窗体(三)   距上篇C#制作高仿360安全卫士窗体(二)也将近一个多月了,这个月事情还是像往常一样的多.不多我也乐在其中,毕竟我做的是我喜欢做的东西.今天特地抽空把怎么制作 ...

  5. C#制作高仿360安全卫士窗体2

    C#制作高仿360安全卫士窗体 继上次C#制作高仿360安全卫士窗体<一>发布之后响应还不错,我的博客放肆雷特也来了不少的新朋友,在这里先谢谢大家的支持!我自己也反复看了一下觉得对不起大家 ...

  6. 高仿360界面的实现(用纯XML和脚本实现)

    源码下载:360UI 本项目XML的桌面渲染依赖GQT开源项目(请感兴趣的朋友加入QQ讨论群:101189702,在群共享文件里下载GQT源码),以下是360界面实现的全部XML代码,所有的代码都在3 ...

  7. 制作高仿QQ的聊天系统(上)—— 布局文件 & 减少过度绘制

    由于没有自己的服务器,我就找了个能实现双方通信的SDK,这个SDK是友盟的用户反馈SDK.本系列的博文关注的不是网络通信,而是如何在网络通信机制已经做好的情况下,做出一个可用的聊天系统.其实,刚开始做 ...

  8. C# WPF仿360安全卫士11

    首先上效果图: 这是我的第一篇随笔,最近因为写一个播放器,开始学习WPF相关技术,随着不断入坑,播放器倒是做出来了,掉坑里了... 本着闲着也是闲着的精神,拿360开刀了: 主界面主要使用DMSkin ...

  9. (原创)高仿360云盘android端的UI实现

    前些日子几大互联网巨头展开了一轮网盘空间大战.一下子从G级别提高到了T级别.以后谁的空间没有1T估计都不好意思开口了~~~ 试用了一下360云盘的客户端,比较小清新(不是给360打广告~~~).刚好U ...

随机推荐

  1. Java SE技术概览 - Jave SE Platform at a Glance

    从学习到工作,使用Java有几年时间,一直没有好好端详一下她的“内涵”.无意中看到一个关于Java SE的概览图,发现Java中提供的API还挺系统全面,把她放到博客中,相信对于想系统了解Java技术 ...

  2. struts2 最新漏洞 S2-016、S2-017修补方案

    昨天struts2爆了一个好大的漏洞,用道哥的话来说就是:“今天下午整个中国的黑客圈像疯了一样开始利用这个漏洞黑网站,大家可以感受一下.” 看下乌云这两天的数据: 相关报道: 灾难日:中国互联网惨遭S ...

  3. ASP.NET状态保持:ViewState

    ViewState是ASP.NET的.aspx页面特有的,是页面级的状态保持.一般用在内网系统和网站后台. namespace WebFormTest.TestCollect { public par ...

  4. 遇到Wampserver遇到的问题

  5. Custom Sort Order

    When trying to sort based on values that do not fit the standard ascending and descending sort logic ...

  6. Zookeeper 脑裂

    转自 http://blog.csdn.net/u010185262/article/details/49910301 Zookeeper zookeeper是一个分布式应用程序的协调服务.它是一个为 ...

  7. C# Async与Await用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. Index of my articles

    65:一个表格说明RelativeLayout中的几个重要属性[Written By KillerLegend] (2013-10-16 21:59) 64:win7修改软件[授权给…]后面的名称 ( ...

  9. Delphi For Android 开发笔记 1 - 开发工具介绍

    在开始前,推荐喜欢delphi或者pascal的朋友,如果想将原来Windows的软件工程移植到Android,可使用CodeTyphon+Delphi XE7进行开发. 1.CodeTyphon C ...

  10. 【Delphi】从内存(MemoryStream)使用WMP(WindowsMediaPlayer)控件播放视频音频(Play Video with WMP from MemoryStream)

    关键字: MemoryStream.WMP.WindowsMediaPlayer.Play .Load. Delphi.C++.C#.ActiveX控件 作  者: CaiBirdy 问  题:正常使 ...